示例#1
0
文件: main.go 项目: 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)
}
示例#2
0
文件: middleware.go 项目: cyx/busl
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)
	}
}