go mod initgo build -o out./outgo build -o out && ./outA fileserver is a kind of simple web server that serves static files from the host machine. File servers are often used to serve static assets for a website, like:
- HTML
- CSS
- JavaScript
- Images
- Create file 'index.html'
- Add line in 'main.go':
mux.Handle("/", http.FileServer(http.Dir(".")))
An http.Handler is any type that implements the ServeHTTP method:
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}The http.ServeMux is an http.Handler You use a Handler for more complex use cases, such as:
- Implement custom router
- Middleware
- any other custom logic
You will tipically use a HandlerFunc when you want to implement a simple handler.