4 ms·
For the file server use the built in FileServer: http://golang.org/pkg/net/http/#FileServer http://golang.org/pkg/net/http/#FileServer For authorization:
by cdoxsey 13y ago
For the file server use the built in FileServer:
http://golang.org/pkg/net/http/#FileServer http://golang.org/pkg/net/http/#FileServer
For authorization:
var siteAuth = base64.StdEncoding.EncodeToString([]byte("USERNAME:PASSWORD"))
func handle(w http.ResponseWriter, r *http.Request) {
auth := r.Header.Get("Authorization")
if auth != "Basic "+siteAuth {
w.Header().Set("WWW-Authenticate", "Basic realm=\"REALM\"")
http.Error(w, "Not Authorized", 401)
return
}
}
No real need for a library.