Skip to content

Instantly share code, notes, and snippets.

@petitviolet
Last active April 5, 2019 00:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save petitviolet/bff05fd9c51b5059a36310e0477c4be1 to your computer and use it in GitHub Desktop.
Save petitviolet/bff05fd9c51b5059a36310e0477c4be1 to your computer and use it in GitHub Desktop.
static file server written in golang.
package main
import (
"log"
"net/http"
)
func main() {
log.Println("Server started. 0.0.0.0:8080")
http.ListenAndServe(":8080", http.HandlerFunc(fileHandler))
}
func fileHandler(w http.ResponseWriter, r *http.Request) {
fileServer := http.FileServer(http.Dir("static"))
log.Printf("url: %s:%s. header = %s", r.Method, r.URL.Path, r.Header)
fileServer.ServeHTTP(w, r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment