rest

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(e *echo.Echo, log zerolog.Logger, port string, opts ...Option)

Start configures logging, recovery, CORS and server timeouts on e and serves on port. It always sets a 10s read-header timeout and a 120s idle timeout. The read and write timeouts are unset (unlimited) unless WithReadTimeout or WithWriteTimeout is passed.

Without WithAllowedOrigins every origin is allowed, and without WithBodyLimit request bodies are unbounded, so production callers should pass both.

Types

type Option added in v1.16.0

type Option func(*config)

Option configures Start.

func WithAllowedOrigins added in v1.16.0

func WithAllowedOrigins(origins ...string) Option

WithAllowedOrigins restricts CORS to the given origins. Without it, or with no origins, every origin is allowed.

func WithBodyLimit added in v1.16.0

func WithBodyLimit(limit string) Option

WithBodyLimit caps request bodies using echo's BodyLimit middleware, e.g. "10M". Larger bodies get 413. An invalid limit panics when the server is configured. Without it bodies are unbounded.

func WithCredentialedCORS added in v1.18.0

func WithCredentialedCORS() Option

WithCredentialedCORS sends Access-Control-Allow-Credentials: true, so a browser app on another origin can send and receive cookies. It is needed for cookie-based session auth from another origin. It only takes effect together with WithAllowedOrigins: browsers reject credentials with a wildcard origin, so without allowed origins it is ignored and Start logs a warning. The cookie path also needs the origin checks of requests.WithCookie (the CSRF rule in docs/auth.md), since CORS alone does not stop cross-site writes.

func WithIdleTimeout added in v1.16.0

func WithIdleTimeout(d time.Duration) Option

WithIdleTimeout overrides the default 120s keep-alive idle timeout.

func WithReadHeaderTimeout added in v1.16.0

func WithReadHeaderTimeout(d time.Duration) Option

WithReadHeaderTimeout overrides the default 10s read-header timeout.

func WithReadTimeout added in v1.17.0

func WithReadTimeout(d time.Duration) Option

WithReadTimeout caps the time to read a whole request, headers and body, so a client trickling body bytes cannot hold a connection open. It is off by default (zero means unlimited). Uploads that take longer than d are cut off, so size it for the slowest upload the service accepts.

func WithWriteTimeout added in v1.17.0

func WithWriteTimeout(d time.Duration) Option

WithWriteTimeout caps the time from the end of reading the request headers to the end of writing the response. It is off by default (zero means unlimited). Long-running handlers, large downloads and streaming or SSE responses that take longer than d are cut off, so only set it on services that do none of those.

Directories

Path Synopsis
Package generator derives an OpenAPI 3.0 document from the source of an Echo application built on compose's rest handlers.
Package generator derives an OpenAPI 3.0 document from the source of an Echo application built on compose's rest handlers.
Package reference renders an OpenAPI 3.x document as a self-hosted API reference page: an alternative to Scalar and Redoc that ships inside the backend, with no CDN assets.
Package reference renders an OpenAPI 3.x document as a self-hosted API reference page: an alternative to Scalar and Redoc that ships inside the backend, with no CDN assets.

Jump to

Keyboard shortcuts

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