HttpStaticFiles

Alex Tan edited this page Jul 10, 2016 · 5 revisions

Serving Static Files with HTTP

The HTTP package provides good support for efficiently serving static files.

This is a complete Go webserver serving static files:

package main

import "net/http"

func main() {
	panic(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}

That example is intentionally short to make a point. Using panic() to deal with an error is probably too aggressive & would produce too much output.

See net/http documentation and in particular the FileServer example for a more typical example.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.