xecho

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 13 Imported by: 2

Documentation

Index

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

func GetCtx[T any](c echo.Context, key string) (T, bool)

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

func KeyAuthErrorHandler(err error, _ echo.Context) error

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

func LoggerSkipper(c echo.Context) bool

LoggerSkipper skip the heartbeat /status log

func MustGetCtx added in v0.0.2

func MustGetCtx[T any](c echo.Context, key string) T

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

func SetCtx[T any](c echo.Context, key string, val T)

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

func (Paginator) AddHeader

func (p Paginator) AddHeader(c echo.Context, total int64)

AddHeader to echo resp

func (Paginator) Apply

func (p Paginator) Apply(tx *gorm.DB) *gorm.DB

Apply paginator to gorm query

func (Paginator) Offset

func (p Paginator) Offset() int

Offset will used by db query

type SkipRule

type SkipRule struct {
	Method     string
	Path       string
	StatusCode int
}

SkipRule must be fully equal

type Skipper

type Skipper func(ctx echo.Context) bool

func NewSkipper

func NewSkipper(rules []SkipRule) Skipper

NewSkipper gen a logger skipper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL