diff options
| author | Horus3 | 2015-05-08 12:15:49 +0200 |
|---|---|---|
| committer | Horus3 | 2015-05-08 12:15:49 +0200 |
| commit | 8eb35d070a995df4408ae11c07c24c03e29816f1 (patch) | |
| tree | ecd3e6dfdc3adb0a13d142eebdb9dd3114ba0c3d | |
| download | uhttpd-8eb35d070a995df4408ae11c07c24c03e29816f1.tar.gz | |
Initial commit.
| -rw-r--r-- | main.go | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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))))) +} |
