Skip to content

Instantly share code, notes, and snippets.

@simonhayward
Created August 21, 2020 06:43
Show Gist options
  • Save simonhayward/910470800c71279533d8bd93e640c67e to your computer and use it in GitHub Desktop.
Save simonhayward/910470800c71279533d8bd93e640c67e to your computer and use it in GitHub Desktop.
simple static server
package main
import (
"log"
"net/http"
)
func logRequest(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() {
fs := http.FileServer(http.Dir("./"))
http.Handle("/", fs)
log.Println("Listening on :8000...")
err := http.ListenAndServe(":8000", logRequest(http.DefaultServeMux))
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment