func checkAuth(r *http.Request) bool { username, password, ok := r.BasicAuth() if ok == false { return false } return username == "user" && password == "pass" } func rootHandler(w http.ResponseWriter, r *http.Request) { if checkAuth(r) == false { w.Header().Set("WWW-Authenticate", `Basic realm="MY REALM"`) w.WriteHeader(401) w.Write([]byte("401 Unauthorized\n")) return } ... } func main() { http.H