Esempio n. 1
0
func authHandler(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		u, p, ok := r.BasicAuth()
		if ok && u == "foobar" && p == "foobared" {
			ctx := httpmux.Context(r)
			ctx = context.WithValue(ctx, "user", u)
			httpmux.SetContext(ctx, r)
			next(w, r)
			return
		}
		w.Header().Set("WWW-Authenticate", `realm="restricted"`)
		w.WriteHeader(http.StatusUnauthorized)
	}
}
Esempio n. 2
0
// Errorln associates message v with the request context.
func Errorln(r *http.Request, v ...interface{}) {
	ctx := httpmux.Context(r)
	ctx = context.WithValue(ctx, ErrorID, fmt.Sprintln(v...))
	httpmux.SetContext(ctx, r)
}
Esempio n. 3
0
// Errorf associates message v with the request context.
func Errorf(r *http.Request, format string, v ...interface{}) {
	ctx := httpmux.Context(r)
	ctx = context.WithValue(ctx, ErrorID, fmt.Sprintf(format, v...))
	httpmux.SetContext(ctx, r)
}