route

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package route will hold the routes and route groups

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthenticationRequired = errors.New("authentication required")

Functions

func RegisterRoutes

func RegisterRoutes(router *Router) error

RegisterRoutes with the echo routers - Router is defined within openapi.go

Types

type Config added in v0.25.0

type Config struct {
	// Path is the route path pattern.
	Path string
	// Method is the HTTP method for the route.
	Method string
	// Name is the OpenAPI summary for the route.
	Name string
	// Description is the OpenAPI description for the route.
	Description string
	// Tags are the OpenAPI tags for grouping.
	Tags []string
	// OperationID is the OpenAPI operation ID.
	OperationID string
	// Security defines OpenAPI security requirements for the route.
	Security *openapi3.SecurityRequirements
	// Middlewares are applied before the handler.
	Middlewares []echo.MiddlewareFunc
	// RateLimit applies a dedicated per-route rate limiter ahead of the route middleware when set and enabled.
	RateLimit *ratelimit.Config
	// Handler is the handler function wired into the route.
	Handler func(echo.Context) error
	// IncludeInOAS publishes this route in the OpenAPI specification. The
	// published surface is opt-in: only routes explicitly intended for
	// external consumers are documented, everything else stays private.
	IncludeInOAS bool
	// PublicCORS serves the route with a wildcard, credential-less CORS policy, for fully public
	// token-authorized endpoints called cross-origin from arbitrary domains (e.g. trust centers);
	// only supported for static paths (no path parameters)
	PublicCORS bool
}

Config holds the configuration for a route with automatic OpenAPI registration

type Router

type Router struct {
	// Echo is the underlying Echo router instance.
	Echo *echo.Echo
	// OAS is the OpenAPI spec being assembled.
	OAS *openapi3.T
	// Handler provides the HTTP handlers wired into routes.
	Handler *handlers.Handler
	// StartConfig holds Echo start configuration.
	StartConfig *echo.StartConfig
	// LocalFilePath points to static file roots for local assets.
	LocalFilePath string
	// Logger is the Echo logger used by the router.
	Logger *echo.Logger
	// SchemaRegistry registers and resolves OpenAPI schemas.
	SchemaRegistry handlers.SchemaRegistry
	// SpecInstances maps qualified model type names to instances for schema reflection; populated
	// from the generated instances file, only in spec-build mode
	SpecInstances map[string]any
	// SpecTypes accumulates every model type name the analyzed handlers need, used by the instance
	// emitter and to detect missing instances after registration
	SpecTypes map[string]bool
}

Router is a struct that holds the echo router, the OpenAPI schema, and the handler - it's a way to group these components together

func (*Router) AddEchoOnlyRoute

func (r *Router) AddEchoOnlyRoute(route echo.Routable) error

AddEchoOnlyRoute is used to add a route to the echo router without adding it to the OpenAPI schema

func (*Router) AddUnversionedHandlerRoute added in v0.25.0

func (r *Router) AddUnversionedHandlerRoute(config Config) error

AddUnversionedHandlerRoute adds a route to the base group and, in spec-build mode, its derived operation

func (*Router) AddV1HandlerRoute added in v0.25.0

func (r *Router) AddV1HandlerRoute(config Config) error

AddV1HandlerRoute adds a route to the v1 group and, in spec-build mode, its derived operation

func (*Router) Base

func (r *Router) Base() *echo.Group

Base returns the base echo group - no "version" prefix for the router group

func (*Router) VersionOne

func (r *Router) VersionOne() *echo.Group

VersionOne returns a new echo group for version 1 of the API

func (*Router) VersionTwo

func (r *Router) VersionTwo() *echo.Group

VersionTwo returns a new echo group for version 2 of the API - lets anticipate the future

type RouterOption added in v0.3.0

type RouterOption func(*Router)

RouterOption is an option function that can be used to configure the router

func WithEcho added in v0.3.0

func WithEcho(e *echo.Echo) RouterOption

WithEcho is a RouterOption that allows the echo router to be set on the router

func WithHandler added in v0.3.0

func WithHandler(h *handlers.Handler) RouterOption

WithHandler is a RouterOption that allows the handler to be set on the router

func WithHideBanner added in v0.3.0

func WithHideBanner() RouterOption

WithHideBanner is a RouterOption that allows the banner to be hidden on the echo server

func WithLocalFiles added in v0.6.10

func WithLocalFiles(lf string) RouterOption

WithLocalFiles is a RouterOption that allows the local files to be set on the router

func WithLogger added in v0.8.6

func WithLogger(logger *echo.Logger) RouterOption

WithLogger is a RouterOption that allows the logger to be set on the router

func WithOptions added in v0.3.0

func WithOptions(opts ...RouterOption) RouterOption

WithOptions is a RouterOption that allows multiple options to be set on the router

Jump to

Keyboard shortcuts

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