Documentation
¶
Index ¶
- func ErrorHandler() echo.HTTPErrorHandler
- func GetCtx[T any](c echo.Context, key string) (T, bool)
- func KeyAuthConfig() echo.MiddlewareFunc
- func KeyAuthErrorHandler(err error, _ echo.Context) error
- func LoggerMid() echo.MiddlewareFunc
- 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() echo.MiddlewareFunc
KeyAuthConfig returns a middleware config with custom error handler. Use this with echo middleware.KeyAuth.
Example:
e.Use(middleware.KeyAuth(func(key string, c echo.Context) (bool, error) {
return key == "valid-key", nil
}, KeyAuthConfig()))
func KeyAuthErrorHandler ¶
KeyAuthErrorHandler is custom error handler for echo KeyAuth middleware. If this is not set, it's will convert all validator error to 400 error
func LoggerMid ¶
func LoggerMid() echo.MiddlewareFunc
LoggerMid skip /status endpoint, will be deprecated.
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 thank https://github.com/brpaz/echozap
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