Documentation
¶
Index ¶
- Constants
- func BindAndValidate(c *echo.Context, target any) error
- func NewErrorHandler(logger *slog.Logger) echo.HTTPErrorHandler
- func NewValidator() echo.Validator
- func SendJSONError(ctx *echo.Context, status int, title string, opts ...ErrorOption) error
- type Error
- type ErrorOption
- type Option
- func WithBodyLimit(limit int64) Option
- func WithCORSAllowOrigins(allowedOrigins []string) Option
- func WithGracefulTimeout(d time.Duration) Option
- func WithLivenessCheck(check func(context.Context) error) Option
- func WithLogger(logger *slog.Logger) Option
- func WithRateLimiter(cacheEngine cache.Engine, rate int, burst int, ttl time.Duration) Option
- func WithReadTimeout(d time.Duration) Option
- func WithReadinessCheck(check func(context.Context) error) Option
- func WithReadinessCheckTimeout(timeout time.Duration) Option
- func WithReadinessContext(ctx context.Context) Option
- func WithStaticRoot(root string) Option
- func WithSwaggerDarkStyle(enabled bool) Option
- func WithSwaggerRoot(root string) Option
- func WithTracing(enabled bool) Option
- func WithTrustedProxyCIDRs(cidrs []string) Option
- func WithWriteTimeout(d time.Duration) Option
- type Server
Constants ¶
const ( ReadyStatusStarting int32 = iota ReadyStatusServing ReadyStatusShuttingDown )
const MIMEApplicationProblemJSON = "application/problem+json"
Variables ¶
This section is empty.
Functions ¶
func BindAndValidate ¶ added in v0.9.79
BindAndValidate binds request data and validates it with the registered Echo validator. Errors are returned for the HTTP error handler to render.
func NewErrorHandler ¶ added in v0.9.79
func NewErrorHandler(logger *slog.Logger) echo.HTTPErrorHandler
NewErrorHandler renders HTTP errors, including validation details, as problem JSON.
func NewValidator ¶ added in v0.9.79
NewValidator adapts the shared struct validator to Echo.
func SendJSONError ¶
Types ¶
type Error ¶
type Error struct {
Type string `json:"type"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail,omitempty"`
Instance string `json:"instance,omitempty"`
Errors []interface{} `json:"errors,omitempty"`
}
Error is JSON error described by RFC9457. @see https://datatracker.ietf.org/doc/html/rfc9457/ @note subtle deviation from rfc - title and status are required.
type ErrorOption ¶
type ErrorOption func(error *Error)
func WithDetail ¶
func WithDetail(detail string) ErrorOption
func WithInstance ¶
func WithInstance(instance string) ErrorOption
func WithValidationErrors ¶
func WithValidationErrors[T validationErrorAccessor](errs ...T) ErrorOption
WithValidationErrors translates various interfaces to json errors.
type Option ¶
type Option func(s *Server)
func WithBodyLimit ¶
WithBodyLimit sets the maximum allowed size of the request body in bytes. The default is 1 MiB. Zero allows only empty request bodies.
func WithCORSAllowOrigins ¶
WithCORSAllowOrigins sets the allowed origins for CORS requests. Nil or empty origins disable CORS, which is the default. Any list containing "*" allows all origins without credentials.
func WithGracefulTimeout ¶
WithGracefulTimeout sets how long Echo waits for active requests during shutdown.
func WithLivenessCheck ¶ added in v0.9.80
WithLivenessCheck sets the local health check. It must return promptly and must not check external dependencies. A nil check always reports healthy.
func WithLogger ¶
WithLogger sets the logger. A nil logger uses a discard logger.
func WithRateLimiter ¶
WithRateLimiter enables/disables rate limiting.
func WithReadTimeout ¶
WithReadTimeout sets the read timeout.
func WithReadinessCheck ¶
WithReadinessCheck sets the readiness check function.
func WithReadinessCheckTimeout ¶
WithReadinessCheckTimeout sets the timeout for the readiness check function.
func WithReadinessContext ¶ added in v0.9.80
WithReadinessContext marks readiness as shutting down when the context is canceled.
func WithStaticRoot ¶
WithStaticRoot sets the root directory for static files. An empty root disables static file serving, which is the default.
func WithSwaggerDarkStyle ¶
WithSwaggerDarkStyle enabled dark theme for swagger UI page
func WithSwaggerRoot ¶
WithSwaggerRoot sets the root for swagger files. An empty root disables Swagger, which is the default. @note given directory should contain folders: v1, v2, etc.
func WithTrustedProxyCIDRs ¶
WithTrustedProxyCIDRs trusts `X-Forwarded-For` values received through the given proxy networks.
func WithWriteTimeout ¶
WithWriteTimeout sets the write timeout.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Errors ¶ added in v0.9.80
Errors reports at most one unexpected termination, including startup failures. It closes when serving ends; shutdown requested through Shutdown closes it without an error.
func (*Server) Register ¶
func (s *Server) Register(adapters ...adapterAccessor)
Register adapters for /
func (*Server) RegisterV1 ¶
func (s *Server) RegisterV1(adapters ...adapterAccessor)
RegisterV1 adapters for /api/v1/