func Middleware(provider Provider) mux.MiddlewareFunc {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			var user *models.User
			var err error
			if token, ok := r.Header[wallet.TokenHeader]; ok {
				addr := ip.FromRequest(r)
				user, err = provider(token[0], addr)
				if err != nil {
					logger.WithFields(logrus.Fields{"ip": addr}).Debugf("error authenticating user")
				}
			} else {
				err = errors.Err(ErrNoAuthInfo)
			}
			next.ServeHTTP(w, r.Clone(context.WithValue(r.Context(), contextKey, result{user, err})))
		})
	}
}
// Middleware tries to authenticate user using request header
Middleware tries to authenticate user using request header
// Middleware tries to authenticate user using request header
func Middleware(provider Provider) mux.MiddlewareFunc {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			var user *models.User
			var err error
			if token, ok := r.Header[wallet.TokenHeader]; ok {
				addr := ip.FromRequest(r)
				user, err = provider(token[0], addr)
				if err != nil {
					logger.WithFields(logrus.Fields{"ip": addr}).Debugf("error authenticating user")
				}
			} else {
				err = errors.Err(ErrNoAuthInfo)
			}
			next.ServeHTTP(w, r.Clone(context.WithValue(r.Context(), contextKey, result{user, err})))
		})
	}
}
func Middleware ( provider Provider ) mux . MiddlewareFunc { return func ( next http . Handler ) http . Handler { return http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { var user * models . User var err error if token , ok := r . Header [ wallet . TokenHeader ] ; ok { addr := ip . FromRequest ( r ) user , err = provider ( token [ 0 ] , addr ) if err != nil { logger . WithFields ( logrus . Fields { " " : addr } ) . Debugf ( " " ) } } else { err = errors . Err ( ErrNoAuthInfo ) } next . ServeHTTP ( w , r . Clone ( context . WithValue ( r . Context ( ) , contextKey , result { user , err } ) ) ) } ) } }
Middleware tries to authenticate user using request header
Middleware tries to authenticate user using request header