I'm working on an API using GoLang. All calls to this API will contain a public_key
(username) and some will also contain a private_key
(password) in the Authorization header.
I'm trying to figure out how to access the Auth header details so that I can check the credentials against a database.
I'm using Julien Schmidt's router and Alice to chain middleware. My setup so far is:
func main() {
session, err := mgo.Dial("conn-string")
if err != nil {
panic(err)
}
defer session.Close()
session.SetMode(mgo.Monotonic, true)
c := appContext{session.DB("db-name")}
commonHandlers := alice.New(context.ClearHandler)
router := NewRouter()
router.Get("/", commonHandlers.Append(basicAuthHandler).ThenFunc(c.mainHandler))
http.ListenAndServe(":5000", router)
}
but I'm not sure how to continue with the basicAuthHandler
function below. If the public_key
is present I need to check that it's valid. The same for the private_key
if that's included.
func basicAuthHandler(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
}
return http.HandlerFunc(fn)
}