Documentation
¶
Index ¶
- Variables
- func Authenticate(queryKeys ...string) gohttputil.Middleware
- func Authorize(f AuthorizeFunc) gohttputil.Middleware
- func FormPayload(r *http.Request) any
- func JSONPayload(r *http.Request) any
- func JWTPayload(r *http.Request) any
- func Logger(next http.Handler) http.Handler
- func PathValuePayload(r *http.Request) any
- func QueryPayload(r *http.Request) any
- func Recover(next http.Handler) http.Handler
- func SetupJWT(setupFuncs ...JWTSetupFunc)
- func ValidateForm(dto any) gohttputil.Middleware
- func ValidateJSON(dto any) gohttputil.Middleware
- func ValidatePathValue(dto any) gohttputil.Middleware
- func ValidateQuery(dto any) gohttputil.Middleware
- type AuthorizeFunc
- type JWT
- type JWTSetupFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultJWT = &JWT{}
DefaultJWT is global JWT instance.
Functions ¶
func Authenticate ¶
func Authenticate(queryKeys ...string) gohttputil.Middleware
Authenticate creates a middleware to verify and parse jwt. By default it will checj Bearer token from Authorization header. But user may specify URL search query keys in queryKeys parameter from which jwt can be collected, verified and parsed. If authentication fails an unauthorized response will be sent to the client. If authentication succeeds request's context key will contain JWT payload if payload type is specified in setup stage.
func Authorize ¶
func Authorize(f AuthorizeFunc) gohttputil.Middleware
Authorize checks if the request is permitted to reach the handler. If AuthorizeFunc f returns true the request reaches the handler else it responds unauthorized to the client.
func FormPayload ¶
FormPayload returns the validated form payload stored in request's context.
func JSONPayload ¶
JSONPayload returns the validated JSON payload stored in request's context.
func JWTPayload ¶
JWTPayload returns the context value containing the JWT payload found in authentication stage.
func PathValuePayload ¶ added in v1.3.0
PathValuePayload returns the validated path parameters stored in request's context.
func QueryPayload ¶
QueryPayload returns the validated form payload stored in request's context.
func SetupJWT ¶
func SetupJWT(setupFuncs ...JWTSetupFunc)
SetupJWT sets up DefaultJWT. Application should setup this once in it's lifetime.
func ValidateForm ¶
func ValidateForm(dto any) gohttputil.Middleware
ValidateForm validates request body and stores validated payload in the request's context.
func ValidateJSON ¶
func ValidateJSON(dto any) gohttputil.Middleware
ValidateJSON validates JSON body and stores validated payload in the request's context.
func ValidatePathValue ¶ added in v1.3.0
func ValidatePathValue(dto any) gohttputil.Middleware
ValidatePathValue validates request path parameters and stores validated payload in the request's context.
func ValidateQuery ¶
func ValidateQuery(dto any) gohttputil.Middleware
ValidateQuery validates request search query and stores validated payload in the request's context.
Types ¶
type AuthorizeFunc ¶
AuthorizeFunc is the signature for request authorizing function.
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT provides interface for setting up JWT token parsing and payload retrieval.
type JWTSetupFunc ¶
JWTSetupFunc is the signature for setting up JWT via builder function.
func JWTWithPayloadType ¶
func JWTWithPayloadType(t any) JWTSetupFunc
JWTWithPayloadType sets the payload data type for JWT paylod. Upon successfull verification and parsing, request context will have a pointer of type t filled with data found from JWT payload.
func JWTWithSecret ¶
func JWTWithSecret(secret string) JWTSetupFunc
JWTWithSecret sets JWT Secret key