Documentation ¶
Index ¶
- Constants
- Variables
- func AuthMiddleware() echo.MiddlewareFunc
- func CorrelationID() echo.MiddlewareFunc
- func CorrelationIDWithConfig(config CorrelationIDConfig) echo.MiddlewareFunc
- func CorsConfig(config hexa.Config) middleware.CORSConfig
- func CurrentUser(uf UserFinderBySub, userSDK hexa.UserSDK) echo.MiddlewareFunc
- func CurrentUserWithConfig(cfg CurrentUserConfig) echo.MiddlewareFunc
- func CurrentUserWithoutFetch(userSDK hexa.UserSDK) echo.MiddlewareFunc
- func DebugMiddleware(e *echo.Echo) echo.MiddlewareFunc
- func DefaultCtxCreator(ctx hexa.Context) hexa.Context
- func GenerateToken(u hexa.User, cfg GenerateTokenConfig) (token, rToken hexa.Secret, err error)
- func GuestMiddleware() echo.MiddlewareFunc
- func HTTPErrorHandler(l hexa.Logger, t hexa.Translator, debug bool) echo.HTTPErrorHandler
- func HexaContext(ctxCreator CtxCreator, logger hexa.Logger, translator hexa.Translator) echo.MiddlewareFunc
- func HexaToEchoLogger(cfg hexa.Config, logger hexa.Logger) echo.Logger
- func IDAsSubjectGenerator(user hexa.User) (string, error)
- func JWT(key hexa.Secret) echo.MiddlewareFunc
- func Recover() echo.MiddlewareFunc
- func RecoverWithConfig(skipper middleware.Skipper) echo.MiddlewareFunc
- func RefreshToken(cfg RefreshTokenConfig) (token, rToken hexa.Secret, err error)
- func RequestID() echo.MiddlewareFunc
- func RequestIDWithConfig(config RequestIDConfig) echo.MiddlewareFunc
- func ResourceAPI(group *echo.Group, resource interface{}, prefix string, ...)
- func SetContextLogger(cfg hexa.Config) echo.MiddlewareFunc
- func UserGateMiddleware(cfg GateMiddlewareConfig) echo.MiddlewareFunc
- type CorrelationIDConfig
- type CreateResource
- type CtxCreator
- type CurrentUserConfig
- type DeleteResource
- type GateMiddlewareConfig
- type GenerateTokenConfig
- type GetResource
- type PatchResource
- type QueryResource
- type RefreshTokenAuthorizer
- type RefreshTokenConfig
- type RequestIDConfig
- type Resource
- type SubGenerator
- type UpdateResource
- type UserFinderBySub
Constants ¶
const ( // ContextKeyHexaRequestID uses as key in context to store request id to use in context middleware ContextKeyHexaRequestID = "__hexa_ctx.rid__" // ContextKeyHexaCorrelationID uses as key in context to store correlation id to use in context middleware ContextKeyHexaCorrelationID = "__hexa_ctx.cid__" // ContextKeyHexaCtx is the identifier to set the hexa context as a field in the context of a request. ContextKeyHexaCtx = "__hexa_ctx.ctx__" // ContextKeyHexaUser is the identifier to set the hexa user as a field in the context of a request. ContextKeyHexaUser = "__hexa_ctx.user__" )
const JwtContextKey = "jwt"
Variables ¶
var ( // HeaderCorrelationID is the http X-Correlation-ID header name. HeaderCorrelationID = "X-Correlation-ID" // DefaultCorrelationIDConfig is the default CorrelationID middleware config. DefaultCorrelationIDConfig = CorrelationIDConfig{ Skipper: middleware.DefaultSkipper, Generator: uuidGenerator, } )
var ( // CurrentUserContextKey is the context key to set // the current user in the request context. CurrentUserContextKey = "user" )
var ( // DefaultRequestIDConfig is the default RequestID middleware config. DefaultRequestIDConfig = RequestIDConfig{ Skipper: middleware.DefaultSkipper, Generator: uuidGenerator, } )
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware() echo.MiddlewareFunc
AuthMiddleware is a middleware that force user to authenticate to access to specific API. AuthMiddleware should be after the HexaContext middleware.
func CorrelationID ¶
func CorrelationID() echo.MiddlewareFunc
CorrelationID returns a X-Request-ID middleware.
func CorrelationIDWithConfig ¶
func CorrelationIDWithConfig(config CorrelationIDConfig) echo.MiddlewareFunc
CorrelationIDWithConfig returns a X-Correlation-ID middleware with config.
func CorsConfig ¶
func CorsConfig(config hexa.Config) middleware.CORSConfig
CORSConfig returns te CORS config.
func CurrentUser ¶
func CurrentUser(uf UserFinderBySub, userSDK hexa.UserSDK) echo.MiddlewareFunc
CurrentUser is a middleware to set the user in the context. If provided jwt, so this function find user and set it as user otherwise set guest user.
func CurrentUserWithConfig ¶
func CurrentUserWithConfig(cfg CurrentUserConfig) echo.MiddlewareFunc
CurrentUser is a middleware to set the user in the context. If provided jwt, so this function find user and set it as user otherwise set guest user.
func CurrentUserWithoutFetch ¶
CurrentUserWithoutFetch is for when you have a gateway that find the user and include it in the jwt. so you will dont need to any user finder.
func DebugMiddleware ¶
func DebugMiddleware(e *echo.Echo) echo.MiddlewareFunc
DebugMiddleware make a route available just in debug mode.
func DefaultCtxCreator ¶
This is default implementation of context creator.
func GenerateToken ¶
GenerateToken generate new token for the user.
func GuestMiddleware ¶
func GuestMiddleware() echo.MiddlewareFunc
GuestMiddleware is a middleware that force user to be guest to access to specific API. GuestMiddleware should be after the hexaContext middleware.
func HTTPErrorHandler ¶
func HTTPErrorHandler(l hexa.Logger, t hexa.Translator, debug bool) echo.HTTPErrorHandler
HTTPErrorHandler is the echo error handler. this function need to the HexaContext middleware.
func HexaContext ¶
func HexaContext(ctxCreator CtxCreator, logger hexa.Logger, translator hexa.Translator) echo.MiddlewareFunc
HexaContext set hexa context on each request.
func HexaToEchoLogger ¶
HexaToEchoLogger convert hexa logger to echo logger.
func IDAsSubjectGenerator ¶
IDAsSubjectGenerator return user's id as jwt subject (sub).
func Recover ¶
func Recover() echo.MiddlewareFunc
Recover returns a middleware which recovers from panics anywhere in the chain and handles the control to the centralized HTTPErrorHandler.
func RecoverWithConfig ¶
func RecoverWithConfig(skipper middleware.Skipper) echo.MiddlewareFunc
RecoverWithConfig returns a Recover middleware with config. See `Recover()` document.
func RefreshToken ¶
func RefreshToken(cfg RefreshTokenConfig) (token, rToken hexa.Secret, err error)
RefreshToken refresh the jwt token by provided config. In provided config to this function set user as just simple hexa guest user. we set it by your authorizer later.
func RequestIDWithConfig ¶
func RequestIDWithConfig(config RequestIDConfig) echo.MiddlewareFunc
RequestIDWithConfig returns a X-Request-ID middleware with config.
func ResourceAPI ¶
func ResourceAPI(group *echo.Group, resource interface{}, prefix string, m ...echo.MiddlewareFunc)
Resource define each method that exists in provided resource.
func SetContextLogger ¶
SetContextLogger set the hexa logger on each context.
func UserGateMiddleware ¶
func UserGateMiddleware(cfg GateMiddlewareConfig) echo.MiddlewareFunc
UserGateMiddleware is a middleware to specify user should be authenticated or be guest to access to specific API.
Types ¶
type CorrelationIDConfig ¶
type CorrelationIDConfig struct { // Skipper defines a function to skip middleware. Skipper middleware.Skipper // Generator defines a function to generate an ID. // Optional. Default value unique uuid. Generator func() string }
CorrelationIDConfig defines the config for CorrelationID middleware.
type CreateResource ¶
type CreateResource interface {
Create(c echo.Context) error
}
type CtxCreator ¶
NewCtx get hexa Context and return itself context.
type CurrentUserConfig ¶
type CurrentUserConfig struct { ExtendJWT bool UserContextKey string JWTContextKey string // contains filtered or unexported fields }
CurrentUserConfig is the config to use in CurrentUser middleware.
type DeleteResource ¶
type DeleteResource interface {
Delete(c echo.Context) error
}
type GateMiddlewareConfig ¶
type GateMiddlewareConfig struct {
MustBeGuest bool
}
type GenerateTokenConfig ¶
type GenerateTokenConfig struct { Secret hexa.Secret ExpireTokenAfter time.Duration ExpireRefreshTokenAfter time.Duration SubGenerator SubGenerator }
GenerateTokenConfig use as config to generate new token.
type GetResource ¶
type GetResource interface {
Get(c echo.Context) error
}
type PatchResource ¶
type PatchResource interface {
Patch(c echo.Context) error
}
type QueryResource ¶
type QueryResource interface {
Query(c echo.Context) error
}
type RefreshTokenAuthorizer ¶
RefreshTokenAuthorizer is a type check that user can get new token.
type RefreshTokenConfig ¶
type RefreshTokenConfig struct { GenerateTokenConfig RefreshToken hexa.Secret // Use Authorizer to verify that can get new token. Authorizer RefreshTokenAuthorizer }
RefreshTokenConfig use as config to refresh access token.
type RequestIDConfig ¶
type RequestIDConfig struct { // Skipper defines a function to skip middleware. Skipper middleware.Skipper // Generator defines a function to generate an ID. // Optional. Default value random.String(32). Generator func() string }
RequestIDConfig defines the config for RequestID middleware.
type UpdateResource ¶
type UpdateResource interface {
Update(c echo.Context) error
}