Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 781 Bytes

README.md

File metadata and controls

30 lines (24 loc) · 781 Bytes

httpbasicauth

CircleCI codecov

An HTTP Basic Auth middleware for Go

Usage

import (
    "net/http"
    "github.com/yspro/httpbasicauth"
)

// credentials
creds := httpbasicauth.SimpleCredentialMap{"u$eR": "$ecret"}
middleware := httpbasicauth.Handle(creds, "Restricted Zone")

yourhandler := http.HandlerFunc(
    func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "Hello World")
    },
)

http.Handle("/secret", middleware(yourhandler))
err := http.ListenAndServe(":8080", nil)
if err != nil {
    panic(err)
}