func main() { auth := authenticater.NewBasicAuth() auth.AddPrincipal("foo", "bar") http.HandleFunc("/", authenticater.WrapAuth(auth, func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello")) })) http.ListenAndServe(":8080", nil) }
func auth(fn http.HandlerFunc) http.HandlerFunc { if *util.Creds == "" { return fn } if auth, err := authenticater.NewBasicAuthFromString(*util.Creds); err != nil { log.Fatalf("server.middleware error=%v", err) return nil } else { return authenticater.WrapAuth(auth, fn) } }