http

package
v0.9.69 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MIMEApplicationProblemJSON = "application/problem+json"

Variables

This section is empty.

Functions

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 string) Option

WithBodyLimit sets the maximum allowed size of the request body. Limit can be specified as 4x or 4xB, where x is one of the multiple from K, M, G, T or P.

func WithCORSAllowOrigins

func WithCORSAllowOrigins(allowedOrigins []string) Option

WithCORSAllowOrigins sets the allowed origins for CORS requests.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger.

func WithRateLimiter

func WithRateLimiter(rate int, burst int) Option

WithRateLimiter enables/disables rate limiting.

func WithReadTimeout

func WithReadTimeout(d time.Duration) Option

WithReadTimeout sets the read timeout.

func WithSonicSerializer

func WithSonicSerializer() Option

WithSonicSerializer uses bytedance/sonic as json serializer

func WithStaticRoot

func WithStaticRoot(root string) Option

WithStaticRoot sets the root directory for static files.

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. @note given directory should contain folders: v1, v2, etc.

func WithTracing

func WithTracing(enabled bool) Option

WithTracing enables/disables tracing.

func WithWriteTimeout

func WithWriteTimeout(d time.Duration) Option

WithWriteTimeout sets the write timeout.

type PanicError

type PanicError struct {
	BaseErr error
	Stack   []byte
}

func (*PanicError) Error

func (e *PanicError) Error() string

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
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