basicauth-go
golang middleware for HTTP basic auth.
router.Use(basicauth.New("MyRealm", map[string][]string{
"bob": {"password1", "password2"},
}))
middleware := basicauth.New("MyRealm", map[string][]string{
"bob": {"password1", "password2"},
})
h := middlware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request)) {
})
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")