type MyFileServer struct {
server http.Handler
}
func (h MyFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
//Свою логику проверки паролей/логинов
if r.Header.Get("login") == "admin" && r.Header.Get("password") == "password" {
h.server.ServeHTTP(w, r)
} else {
http.NotFound(w, r)
}
}
func main() {
fs := MyFileServer{server: http.FileServer(http.Dir("static"))}
http.Handle("/", fs)
http.ListenAndServe(":8000", nil)
}
сделал на header'ах
curl -H "login:admin" -H "password:password" 127.0.0.1:8000/test.txt