summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorHorus32015-05-08 12:15:49 +0200
committerHorus32015-05-08 12:15:49 +0200
commit8eb35d070a995df4408ae11c07c24c03e29816f1 (patch)
treeecd3e6dfdc3adb0a13d142eebdb9dd3114ba0c3d /main.go
downloaduhttpd-8eb35d070a995df4408ae11c07c24c03e29816f1.tar.gz
Initial commit.
Diffstat (limited to 'main.go')
-rw-r--r--main.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..cf428ed
--- /dev/null
+++ b/main.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "net/http"
+ "os"
+)
+
+func accessLog(h http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ log.Println(r.Method, r.URL.Path, r.RemoteAddr)
+ h.ServeHTTP(w, r)
+ })
+}
+
+func main() {
+ ip_f := flag.String("ip", "0.0.0.0", "IP adress to listen on.")
+ port_f := flag.String("port", "3000", "Port to listen on.")
+ dir_f := flag.String("dir", ".", "Directory to serve.")
+
+ flag.Parse()
+
+ port := os.Getenv("PORT")
+ if port == "" {
+ port = *port_f
+ }
+
+ fmt.Println("Starting uhttpd serving \"" + *dir_f + "\" on " + *ip_f + ":" + port + ".")
+ log.Fatal(http.ListenAndServe(*ip_f+":"+port, accessLog(http.FileServer(http.Dir(*dir_f)))))
+}