Skip to content

Instantly share code, notes, and snippets.

@congjf
Created December 26, 2013 01:34
Show Gist options
  • Save congjf/8128658 to your computer and use it in GitHub Desktop.
Save congjf/8128658 to your computer and use it in GitHub Desktop.
Golang Static File Server
Golang Static File Server
func main(){
log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}
func main() {
var router Router
server := &http.Server{
Addr: ":8888",
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(server.ListenAndServe())
}
func (router Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// Other HandlerFunc
FILEHandler(rw, req)
}
func FILEHandler(rw http.ResponseWriter, req *http.Request) {
h := http.FileServer(http.Dir("."))
h.ServeHTTP(rw, req)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment