Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthStatus ¶
type AuthStatus int
AuthStatus is the status that is returned by an authenticator
const ( AuthStatusPass AuthStatus = iota // AuthStatusPass is returned when the authenticator cannot handle or doesn't care. Next authenticator is checked AuthStatusSuccess // AuthStatusSuccess allows the request, no other authenticators are checked AuthStatusFailure // AuthStatusFailure denies the request, no other authenticators are checked )
AuthorizationContext is a context key that defines the authorization method
type Authenticate ¶
type Authenticate struct {
Chain []Authenticator
}
Authenticate holds multiple middleware/authenticators that can authenticate against the API
func (*Authenticate) Add ¶
func (ma *Authenticate) Add(auth Authenticator)
Add a new authenticator to the list
func (*Authenticate) Middleware ¶
func (ma *Authenticate) Middleware(next http.Handler) http.Handler
Middleware JWT token authentication
type Authenticator ¶
type Authenticator interface {
Authenticate(req *http.Request, route string) (AuthStatus, context.Context, error)
}
Authenticator allows you to use the struct in the multi-auth middleware
type ContextKeyType ¶
type ContextKeyType int
ContextKeyType is the type used in context
const ( AuthorizationContext ContextKeyType = iota // Defines which authorization type is used APIKeyContext // Used API key AuthKeyContext // Used Auth key ClaimsContext // Context key for fetching JWT claims AddressContext // Context key for fetching the address from the JWT )
Context keys
type PrettyJSON ¶
type PrettyJSON struct {
http.ResponseWriter
}
PrettyJSON is a middleware that will set a response header based on the request URI. This can be used to output json data either indented or not.
func (*PrettyJSON) Middleware ¶
func (*PrettyJSON) Middleware(next http.Handler) http.Handler
Middleware sets header based on query param
type Tracer ¶
type Tracer struct { http.ResponseWriter // contains filtered or unexported fields }
Tracer is a middleware that logs the URL / status code of the call
func (*Tracer) Middleware ¶
Middleware Prints request in log
func (*Tracer) WriteHeader ¶
WriteHeader writes the given header to the response writer