util/srv/misc.go
func (s *Server) RequireBasicAuth(logger log.Logger,
	handler HandlerFunc, auth AuthFunc) HandlerFunc {
	l := logger.Add("method", "RequireBasicAuth")
	return func(w http.ResponseWriter, r *http.Request, ctx *Context) {
		name, pass, ok := r.BasicAuth()
		if !ok || !auth(name, pass) {
			l.Add("sender", r.RemoteAddr).Warn("access denied")
			s.RespondError(logger, w, ErrAccessDenied)
			return
		}

		ctx.Username = name
		handler(w, r, ctx)
	}
}
func (s *Server) RequireBasicAuth(logger log.Logger,
	handler HandlerFunc, auth AuthFunc) HandlerFunc {
	l := logger.Add("method", "RequireBasicAuth")
	return func(w http.ResponseWriter, r *http.Request, ctx *Context) {
		name, pass, ok := r.BasicAuth()
		if !ok || !auth(name, pass) {
			l.Add("sender", r.RemoteAddr).Warn("access denied")
			s.RespondError(logger, w, ErrAccessDenied)
			return
		}

		ctx.Username = name
		handler(w, r, ctx)
	}
}
func ( s * Server ) RequireBasicAuth ( logger log . Logger , handler HandlerFunc , auth AuthFunc ) HandlerFunc { l := logger . Add ( " " , " " ) return func ( w http . ResponseWriter , r * http . Request , ctx * Context ) { name , pass , ok := r . BasicAuth ( ) if ! ok || ! auth ( name , pass ) { l . Add ( " " , r . RemoteAddr ) . Warn ( " " ) s . RespondError ( logger , w , ErrAccessDenied ) return } ctx . Username = name handler ( w , r , ctx ) } }
// RequireBasicAuth wraps a given handler function inside a handler with basic
// access authentication.
RequireBasicAuth wraps a given handler function inside a handler with basic access authentication .