Created
May 2, 2014 23:29
-
-
Save roktas/11488662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"os" | |
) | |
var port = "8080" | |
var root = "." | |
func handler(h http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
log.Println(r.RemoteAddr, r.Method, r.URL) | |
h.ServeHTTP(w, r) | |
}) | |
} | |
func main() { | |
if env := os.Getenv("PORT"); env != "" { | |
port = env | |
} | |
if args := os.Args; len(args) > 1 { | |
root = args[1] | |
} | |
log.Println("Starting web server at http://0.0.0.0:" + port) | |
panic(http.ListenAndServe(":"+port, handler(http.FileServer(http.Dir(root))))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment