Example #1
0
File: main.go Project: cyx/busl
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)
}
Example #2
0
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)
	}
}