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?
question from:
https://stackoverflow.com/questions/27945310/why-do-i-need-to-use-http-stripprefix-to-access-my-static-files 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…