Help us shape the future of Go! Take the 2026 Go Developer Survey

http

package
v0.9.79 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadyStatusStarting int32 = iota
	ReadyStatusServing
	ReadyStatusShuttingDown
)
View Source
const MIMEApplicationProblemJSON = "application/problem+json"

Variables

This section is empty.

Functions

func BindAndValidate added in v0.9.79

func BindAndValidate(c *echo.Context, target any) error

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

func NewValidator() echo.Validator

NewValidator adapts the shared struct validator to Echo.

func SendJSONError

func SendJSONError(ctx *echo.Context, status int, title string, opts ...ErrorOption) error

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 WitHealthCheckCtx

func WitHealthCheckCtx(ctx context.Context) Option

WitHealthCheckCtx sets the health-check context. Once context is canceled, health-check will return error.

func WithBodyLimit

func WithBodyLimit(limit int64) Option

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

func WithCORSAllowOrigins(allowedOrigins []string) Option

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

func WithGracefulTimeout(d time.Duration) Option

WithGracefulTimeout sets how long Echo waits for active requests during shutdown.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger. A nil logger uses a discard logger.

func WithRateLimiter

func WithRateLimiter(cacheEngine cache.Engine, rate int, burst int, ttl time.Duration) Option

WithRateLimiter enables/disables rate limiting.

func WithReadTimeout

func WithReadTimeout(d time.Duration) Option

WithReadTimeout sets the read timeout.

func WithReadinessCheck

func WithReadinessCheck(check func(context.Context) error) Option

WithReadinessCheck sets the readiness check function.

func WithReadinessCheckTimeout

func WithReadinessCheckTimeout(timeout time.Duration) Option

WithReadinessCheckTimeout sets the timeout for the readiness check function.

func WithStaticRoot

func WithStaticRoot(root string) Option

WithStaticRoot sets the root directory for static files. An empty root disables static file serving, which is the default.

func WithSwaggerDarkStyle

func WithSwaggerDarkStyle(enabled bool) Option

WithSwaggerDarkStyle enabled dark theme for swagger UI page

func WithSwaggerRoot

func WithSwaggerRoot(root string) Option

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 WithTracing

func WithTracing(enabled bool) Option

WithTracing enables/disables tracing.

func WithTrustedProxyCIDRs

func WithTrustedProxyCIDRs(cidrs []string) Option

WithTrustedProxyCIDRs trusts `X-Forwarded-For` values received through the given proxy networks.

func WithWriteTimeout

func WithWriteTimeout(d time.Duration) Option

WithWriteTimeout sets the write timeout.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Server

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/

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Start

func (s *Server) Start(addr string) error

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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