Documentation
¶
Index ¶
- func ErrorHandler() echo.HTTPErrorHandler
- func GetCtx[T any](c *echo.Context, key string) (T, bool)
- func KeyAuthConfig(validator middleware.KeyAuthValidator) middleware.KeyAuthConfig
- func KeyAuthErrorHandler(_ *echo.Context, err error) error
- func LoggerSkipper(c *echo.Context) bool
- func MustGetCtx[T any](c *echo.Context, key string) T
- func NewErrorHandler(logger *zap.Logger) echo.HTTPErrorHandler
- func SetCtx[T any](c *echo.Context, key string, val T)
- func ZapLogger(log *zap.Logger) echo.MiddlewareFunc
- func ZapLoggerWithSkipper(log *zap.Logger, skipper Skipper) echo.MiddlewareFunc
- type Paginator
- type SkipRule
- type Skipper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorHandler ¶ added in v0.0.2
func ErrorHandler() echo.HTTPErrorHandler
ErrorHandler is a convenience function that returns an error handler using a default logger. Use this for quick setup without custom logger configuration.
func GetCtx ¶ added in v0.0.2
GetCtx retrieves a value from the echo context with type safety. T is the type of the value to retrieve. Returns the value and true if found, zero value and false otherwise.
Example:
userID, ok := GetCtx[string](c, "user_id")
if !ok {
return errors.New("user_id not found")
}
func KeyAuthConfig ¶ added in v0.0.2
func KeyAuthConfig(validator middleware.KeyAuthValidator) middleware.KeyAuthConfig
KeyAuthConfig returns an echo KeyAuth middleware config that validates keys with validator and reports missing or invalid keys by KeyAuthErrorHandler.
Example:
e.Use(middleware.KeyAuthWithConfig(xecho.KeyAuthConfig(
func(c *echo.Context, key string, _ middleware.ExtractorSource) (bool, error) {
return subtle.ConstantTimeCompare([]byte(key), []byte("valid-key")) == 1, nil
})))
func KeyAuthErrorHandler ¶
KeyAuthErrorHandler is custom error handler for echo KeyAuth middleware. It converts missing or invalid key errors to a 400 xerr.Error, other errors (e.g. returned by the validator) are passed through.
func LoggerSkipper ¶
LoggerSkipper skip the heartbeat /status log
func MustGetCtx ¶ added in v0.0.2
MustGetCtx retrieves a value from the echo context or panics if not found. Use this when you're certain the value exists.
Example:
userID := MustGetCtx[string](c, "user_id")
func NewErrorHandler ¶
func NewErrorHandler(logger *zap.Logger) echo.HTTPErrorHandler
NewErrorHandler returns a customized echo's HTTP error handler.
func SetCtx ¶ added in v0.0.2
SetCtx stores a value in the echo context with type safety. T is the type of the value to store.
Example:
SetCtx(c, "user_id", "12345") SetCtx(c, "is_admin", true)
func ZapLogger ¶
func ZapLogger(log *zap.Logger) echo.MiddlewareFunc
ZapLogger use zap for echo logger
func ZapLoggerWithSkipper ¶
func ZapLoggerWithSkipper(log *zap.Logger, skipper Skipper) echo.MiddlewareFunc
ZapLoggerWithSkipper use zap as request logger. Errors are handled by the echo error handler before logging, so the logged status is final. The skipper is checked after the request is handled, so it can use the response status. Register it as the first (outermost) middleware, because the response is sent once it handles the error.
Types ¶
type Paginator ¶
type Paginator struct {
Page int `query:"page" validate:"omitempty,min=1"`
PageSize int `query:"page_size" validate:"omitempty,min=5,max=50"`
}
Paginator can be embedded to request struct You can check the input by mod validator If the value is wrong, It would be change to default
type Skipper ¶
type Skipper = middleware.Skipper
Skipper decides whether a request should not be logged.