An open API service indexing awesome lists of open source software.

https://github.com/mpl/basicauth

HTTP basic access authentication
https://github.com/mpl/basicauth

Last synced: about 1 year ago
JSON representation

HTTP basic access authentication

Awesome Lists containing this project

README

          

# basicauth
HTTP basic access authentication

Example:

var up *basicauth.UserPass

func makeHandler(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer func() {
if e, ok := recover().(error); ok {
http.Error(w, e.Error(), http.StatusInternalServerError)
return
}
}()
if up.IsAllowed(r) {
fn(w, r)
} else {
basicauth.SendUnauthorized(w, r, "montorrent")
}
}
}

func main() {
var err error
up, err = basicauth.New("foo:bar")
if err != nil {
log.Fatal(err)
}

http.Handle("/", makeHandler(someHandler))
http.ListenAndServe(*host, nil)
}