Skip to content

Instantly share code, notes, and snippets.

@corehello
Last active March 3, 2021 10:53
Show Gist options
  • Save corehello/ac73095554bc654e22ee to your computer and use it in GitHub Desktop.
Save corehello/ac73095554bc654e22ee to your computer and use it in GitHub Desktop.
The most simple http server in golang like `python -m SimHTTPServer 8000`
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"))))))
}
@corehello
Copy link
Author

will add some logging feature in future

@corehello
Copy link
Author

Add logging done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment