Created
August 21, 2020 06:43
-
-
Save simonhayward/910470800c71279533d8bd93e640c67e to your computer and use it in GitHub Desktop.
simple static server
This file contains 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" | |
) | |
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