Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 930 Bytes

README.md

File metadata and controls

41 lines (29 loc) · 930 Bytes

basicauth-go

GoDoc Build Status

golang middleware for HTTP basic auth.

// Chi

router.Use(basicauth.New("MyRealm", map[string][]string{
    "bob": {"password1", "password2"},
}))


// Manual wrapping

middleware := basicauth.New("MyRealm", map[string][]string{
    "bob": {"password1", "password2"},
})

h := middlware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request)) {
    /// do stuff
})

log.Fatal(http.ListenAndServe(":8080", h))

env loading

If your environment looks like this:

SOME_PREFIX_BOB=password
SOME_PREFIX_JANE=password1,password2

you can load it like this:

middleware := basicauth.NewFromEnv("MyRealm", "SOME_PREFIX")