Back to godoc.org
github.com/Kamva/kitty-echo

Package kecho

v0.0.0-...-fa5849d
Latest Go to latest

The latest major version is .

Published: Mar 3, 2020 | License: MIT | Module: github.com/Kamva/kitty-echo

Index

Constants

const (
	// ContextKeyKittyRequestID uses as key in context to store request id to use in context middleware
	ContextKeyKittyRequestID = "__kitty_ctx.rid__"

	// ContextKeyKittyCorrelationID uses as key in context to store correlation id to use in context middleware
	ContextKeyKittyCorrelationID = "__kitty_ctx.cid__"

	// ContextKeyKittyCtx is the identifier to set the kitty context as a field in the context of a request.
	// e.g ctx.Set(kitty.ContextIdentifier,kittyCtx) // kittyCtx is kitty Context.
	ContextKeyKittyCtx = "__kitty_ctx.ctx__"

	// ContextKeyKittyUser is the identifier to set the kitty user as a field in the context of a request.
	ContextKeyKittyUser = "__kitty_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,
	}
)

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 kittyContext 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 CurrentUser

func CurrentUser(userFinder UserFinderByJwtSub) 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 DebugMiddleware

func DebugMiddleware(e *echo.Echo) echo.MiddlewareFunc

KittyContext set kitty context on each request.

func GenerateToken

func GenerateToken(cfg GenerateTokenConfig) (token, rToken kitty.Secret, err error)

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 kittyContext middleware.

func HTTPErrorHandler

func HTTPErrorHandler(l kitty.Logger, t kitty.Translator, debug bool) echo.HTTPErrorHandler

HTTPErrorHandler is the echo error handler. this function need to the KittyContext middleware.

func IDAsSubjectGenerator

func IDAsSubjectGenerator(user kitty.User) (string, error)

IDAsSubjectGenerator return user's id as jwt subject (sub).

func JWT

func JWT(key kitty.Secret) echo.MiddlewareFunc

JWT middleware

func KittyContext

func KittyContext(logger kitty.Logger, translator kitty.Translator) echo.MiddlewareFunc

KittyContext set kitty context on each request.

func KittyLoggerToEchoLogger

func KittyLoggerToEchoLogger(logger kitty.Logger) echo.Logger

KittyLoggerToEchoLogger convert kitty logger to echo logger.

func RefreshToken

func RefreshToken(cfg RefreshTokenConfig) (token, rToken kitty.Secret, err error)

RefreshToken refresh the jwt token by provided config. In provided config to this function set user as just simple kitty guest user. we set it by your authorizer later.

func RequestID

func RequestID() echo.MiddlewareFunc

RequestID returns a X-Request-ID middleware.

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 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.

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(ctx echo.Context) error
}

type CurrentUserConfig

type CurrentUserConfig struct {
	UserFinderByJwtSub UserFinderByJwtSub
	UserContextKey     string
	JWTContextKey      string
}

CurrentUserConfig is the config to use in CurrentUser middleware.

type DeleteResource

type DeleteResource interface {
	Delete(ctx echo.Context) error
}

type GateMiddlewareConfig

type GateMiddlewareConfig struct {
	MustBeGuest bool
}

type GenerateTokenConfig

type GenerateTokenConfig struct {
	User                    kitty.User
	Secret                  kitty.Secret
	ExpireTokenAfter        time.Duration
	ExpireRefreshTokenAfter time.Duration
	SubGenerator            SubGenerator
}

GenerateTokenConfig use as config to generate new token.

type GetResource

type GetResource interface {
	Get(ctx echo.Context) error
}

type PatchResource

type PatchResource interface {
	Patch(ctx echo.Context) error
}

type QueryResource

type QueryResource interface {
	Query(ctx echo.Context) error
}

type RefreshTokenAuthorizer

type RefreshTokenAuthorizer func(sub string) (kitty.User, error)

RefreshTokenAuthorizer is a type check that user can get new token.

type RefreshTokenConfig

type RefreshTokenConfig struct {
	GenerateTokenConfig
	RefreshToken kitty.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 Resource

type Resource struct {
}

func (Resource) Ctx

func (r Resource) Ctx(c echo.Context) kitty.Context

Ctx method extract the kitty context from the echo context.

type SubGenerator

type SubGenerator func(user kitty.User) (string, error)

type UpdateResource

type UpdateResource interface {
	Update(ctx echo.Context) error
}

type UserFinderByJwtSub

type UserFinderByJwtSub func(sub string) (kitty.User, error)

UserFinderByJwtSub is a function to use to find current user by jwt claims.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier