4 ms·
Does anyone know a simple way to get a go file webserver with traditional auth (plain/digest) ?
by waps 13y ago
Does anyone know a simple way to get a go file webserver with traditional auth (plain/digest) ?
- cdoxsey 13y agoFor 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.