APIKey
Overview
APIKey validates a header API key and stores it on the request context.
Part of the auth package — Node.js analog: passport.
Signature
go
func APIKey(header string, opts APIKeyOpts) goxhttp.MiddlewareCompare: Node.js · Standard Go · gox
js
// Typical passport pattern in Node.jsgo
// net/http middleware checking Authorization headergo
import "github.com/sahilkhaire/gox/auth"
app.Use(auth.APIKey("X-API-Key", auth.APIKeyOpts{Keys: map[string]bool{"dev-key": true}}))Example
go
import "github.com/sahilkhaire/gox/auth"
app.Use(auth.APIKey("X-API-Key", auth.APIKeyOpts{Keys: map[string]bool{"dev-key": true}}))Tips
Import github.com/sahilkhaire/gox/auth and call APIKey directly. See the comparison below for the standard library equivalent.
Standard library alternative
gox wraps the Go standard library or a trusted dependency with Node-familiar naming. You can use the underlying library directly — see the package overview for escape hatches.