main.go
package main
import (
"net/http"
)
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.ListenAndServe(":8080", nil)
}
Directory structure:
%GOPATH%/src/project_name/main.go
%GOPATH%/src/project_name/static/..files and folders ..
Even after reading the documentation I have trouble understanding what exactly http.StripPrefix
does here.
1) Why can't I access localhost:8080/static
if I remove http.StripPrefix
?
2) What URL maps to /static
folder if I remove that function?
http.Handle("/static/", http.FileServer(http.Dir("")))
works.