Last active
March 3, 2021 10:53
-
-
Save corehello/ac73095554bc654e22ee to your computer and use it in GitHub Desktop.
The most simple http server in golang like `python -m SimHTTPServer 8000`
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" | |
) | |
func Log(handler http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
log.Printf("%s %s %s\n", r.RemoteAddr, r.Method, r.URL) | |
handler.ServeHTTP(w, r) | |
}) | |
} | |
func main() { | |
// Simple static webserver: | |
log.Fatal(http.ListenAndServe(":"+os.Args[1], Log(http.FileServer(http.Dir(os.Getenv("PWD")))))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add logging done