route

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package route provides Runa route primitives.

Index

Constants

View Source
const (
	LocalRequestID = "request_id"
	LocalIP        = "ip"
	LocalScheme    = "scheme"
	LocalHost      = "host"
)

Variables

This section is empty.

Functions

func CollectInputSchema

func CollectInputSchema(input any) []validate.FieldSchema

CollectInputSchema collects binding metadata from an input value.

func Cookie[T any](ctx *Context, name string, fallback ...T) T

Cookie returns a cookie value cast to T.

func ErrorCode

func ErrorCode(err error) string

ErrorCode returns a stable error code represented by err.

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage returns the public error message represented by err.

func ErrorParams

func ErrorParams(err error) core.Map

ErrorParams returns translation/rendering parameters represented by err.

func ErrorStatus

func ErrorStatus(err error) int

ErrorStatus returns the HTTP status represented by err.

func Form

func Form[T any](ctx *Context, name string, fallback ...T) T

Form returns a form value cast to T.

func Header[T any](ctx *Context, name string, fallback ...T) T

Header returns a request header cast to T.

func Input

func Input[T any](ctx *Context) (*T, error)

Input binds and validates request data into T.

func InputSchema

func InputSchema[T any]() []validate.FieldSchema

InputSchema collects binding metadata from input struct tags.

func ListCommand

func ListCommand(registry *Registry) runacommand.Command

ListCommand creates a command that lists registered routes.

func Listen

func Listen(ctx context.Context, addr string) error

Listen starts a standalone HTTP server for the default route registry.

func Meta

func Meta[T any](ctx *Context, key string, fallback ...T) T

Meta reads current route metadata cast to T.

func MetaAs

func MetaAs[T any](route *Route, key string, fallback ...T) T

MetaAs reads route metadata cast to T.

func MountDomain

func MountDomain(name string, fn func(*Group))

MountDomain mounts routes into a named domain on the default route registry.

func MountGroup

func MountGroup(name string, fn func(*Group))

MountGroup mounts routes into a named group on the default route registry.

func PanicError

func PanicError(value any, stack ...bool) error

PanicError converts a recovered panic value into a route error.

func Param

func Param[T any](ctx *Context, name string, fallback ...T) T

Param returns a path parameter cast to T.

func Provider

func Provider(options ...ProviderOption) provider.Provider

Provider creates the route provider.

func Query

func Query[T any](ctx *Context, name string, fallback ...T) T

Query returns a query value cast to T.

func Service

func Service[T any](ctx *Context, name ...string) T

Service returns an app-scoped service injected by the route registry.

func Use

func Use(middlewares ...Middleware)

Use appends root middlewares to the default route registry.

Types

type AssetResolver

type AssetResolver interface {
	URL(domain string, path string) string
}

AssetResolver resolves public asset URLs without coupling route to an asset package.

type Context

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

Context is Runa's HTTP request context.

func NewContext

func NewContext(writer http.ResponseWriter, request *http.Request, route *Route, params map[string]string, requestScope ...*scope.Scope) *Context

NewContext creates a route context.

func (*Context) AddSaver

func (ctx *Context) AddSaver(save func(context.Context) error)

AddSaver registers a response-time saver.

func (*Context) Asset

func (ctx *Context) Asset(path string, domains ...string) string

Asset returns a public asset URL.

func (*Context) Bind

func (ctx *Context) Bind(input any) error

Bind binds request data into a struct pointer.

func (*Context) Blob

func (ctx *Context) Blob(contentType string, body []byte) error

Blob writes bytes with an explicit content type using the pending status.

func (*Context) Body

func (ctx *Context) Body() ([]byte, error)

Body reads the request body and restores it for later reads.

func (*Context) Config

func (ctx *Context) Config(name ...string) *config.Store

Config returns the app config store or a named config view.

func (*Context) Context

func (ctx *Context) Context() context.Context

Context returns the request context.

func (*Context) CookieValue

func (ctx *Context) CookieValue(name string) (string, bool)

CookieValue returns a raw cookie value.

func (*Context) Error

func (ctx *Context) Error(status int, value any, params ...core.Map) error

Error creates a route-layer HTTP error.

func (*Context) File

func (ctx *Context) File(name string) (*multipart.FileHeader, bool)

File returns the first uploaded file for a form field.

func (*Context) HTML

func (ctx *Context) HTML(body string) error

HTML writes an HTML response using the pending status.

func (*Context) HeaderString

func (ctx *Context) HeaderString(name string) string

HeaderString returns a request header as string.

func (*Context) Host

func (ctx *Context) Host() string

Host returns the request host.

func (*Context) Hostname

func (ctx *Context) Hostname() string

Hostname returns the request hostname without port.

func (*Context) IP

func (ctx *Context) IP() string

IP returns the client IP.

func (*Context) JSON

func (ctx *Context) JSON(body any) error

JSON writes a JSON response using the pending status.

func (*Context) Lang

func (ctx *Context) Lang() string

Lang returns the current request language.

func (*Context) Locals

func (ctx *Context) Locals(key string, value ...any) any

Locals gets or sets request-local data.

func (*Context) Meta

func (ctx *Context) Meta(key string) any

Meta reads current route metadata as any.

func (*Context) ParamString

func (ctx *Context) ParamString(name string) string

ParamString returns a path parameter as string.

func (*Context) QueryString

func (ctx *Context) QueryString(name string) string

QueryString returns a query value as string.

func (*Context) Redirect

func (ctx *Context) Redirect(url string, status ...int) error

Redirect redirects the request using the pending status or 302.

func (*Context) Render

func (ctx *Context) Render(name string, data any, views ...string) error

Render renders a template response.

func (*Context) RenderOutput

func (ctx *Context) RenderOutput(output any) error

RenderOutput renders a typed output value.

func (*Context) Request

func (ctx *Context) Request() *http.Request

Request returns the underlying request.

func (*Context) RequestID

func (ctx *Context) RequestID() string

RequestID returns the current request id.

func (*Context) Response

func (ctx *Context) Response() http.ResponseWriter

Response returns the underlying response writer.

func (*Context) Route

func (ctx *Context) Route() *Route

Route returns the matched route metadata.

func (*Context) Scheme

func (ctx *Context) Scheme() string

Scheme returns the request scheme.

func (*Context) Scope

func (ctx *Context) Scope() *scope.Scope

Scope returns the request scope.

func (*Context) Send

func (ctx *Context) Send(body []byte) error

Send writes a bytes response using the pending status.

func (*Context) SendFile

func (ctx *Context) SendFile(path string) error

SendFile writes a file response.

func (*Context) SendStatus

func (ctx *Context) SendStatus(code int) error

SendStatus writes an empty response with status.

func (*Context) SendStream

func (ctx *Context) SendStream(reader io.Reader, contentType ...string) error

SendStream writes a stream response using the pending status.

func (*Context) Set

func (ctx *Context) Set(name string, value string) *Context

Set sets a response header.

func (*Context) SetContext

func (ctx *Context) SetContext(value context.Context) *Context

SetContext replaces the underlying request context.

func (*Context) SetCookie

func (ctx *Context) SetCookie(name string, value string, options ...func(*http.Cookie))

SetCookie writes a response cookie.

func (*Context) SetLang

func (ctx *Context) SetLang(value string) *Context

SetLang sets the current request language.

func (*Context) SetRequest

func (ctx *Context) SetRequest(request *http.Request)

SetRequest replaces the request used by this context.

func (*Context) SetResponse

func (ctx *Context) SetResponse(writer http.ResponseWriter)

SetResponse replaces the response writer used by this context.

func (*Context) Status

func (ctx *Context) Status(code int) *Context

Status sets the response status for the next response write.

func (*Context) StatusCode

func (ctx *Context) StatusCode(fallback ...int) int

StatusCode returns the pending or route default success status.

func (*Context) T

func (ctx *Context) T(message string, params ...core.Map) string

T translates a message using current request language.

func (*Context) Text

func (ctx *Context) Text(body string) error

Text writes a plain text response using the pending status.

func (*Context) Type

func (ctx *Context) Type(contentType string) *Context

Type sets the response content type.

func (*Context) Validate

func (ctx *Context) Validate(input any) error

Validate runs input Validate(v) rules when implemented.

func (*Context) ViewDomain

func (ctx *Context) ViewDomain(name string) *Context

ViewDomain sets the request-local default view domain.

func (*Context) XML

func (ctx *Context) XML(body any) error

XML writes an XML response using the pending status.

type DefaultErrorRenderer

type DefaultErrorRenderer struct{}

DefaultErrorRenderer renders errors as plain text.

func (DefaultErrorRenderer) RenderError

func (DefaultErrorRenderer) RenderError(ctx *Context, err error) error

RenderError renders a plain text error.

type Envelope

type Envelope interface {
	Wrap(*Context, any) (any, error)
}

Envelope wraps successful response data.

type EnvelopeFunc

type EnvelopeFunc func(*Context, any) (any, error)

EnvelopeFunc adapts a function to Envelope.

func (EnvelopeFunc) Wrap

func (fn EnvelopeFunc) Wrap(ctx *Context, data any) (any, error)

Wrap wraps response data.

type ErrorHandler

type ErrorHandler func(*Context, error) error

ErrorHandler normalizes route errors.

type ErrorPipeline

type ErrorPipeline struct {
	OnError  ErrorHandler
	Renderer ErrorRenderer
}

ErrorPipeline handles route errors.

func (ErrorPipeline) Handle

func (pipeline ErrorPipeline) Handle(ctx *Context, err error) error

Handle normalizes and renders an error.

type ErrorRenderer

type ErrorRenderer interface {
	RenderError(*Context, error) error
}

ErrorRenderer renders route errors.

type ErrorRendererFunc

type ErrorRendererFunc func(*Context, error) error

ErrorRendererFunc adapts a function to ErrorRenderer.

func (ErrorRendererFunc) RenderError

func (fn ErrorRendererFunc) RenderError(ctx *Context, err error) error

RenderError renders an error.

type Group

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

Group is a route registration scope.

func Domain

func Domain(name string, prefix string, fn ...func(*Group)) *Group

Domain registers a domain on the default route registry.

func GetDomain

func GetDomain(name string) *Group

GetDomain returns a named domain from the default route registry.

func GetGroup

func GetGroup(name string) *Group

GetGroup returns a named group from the default route registry.

func NewGroup

func NewGroup(registry *Registry, prefix string, middlewares ...Middleware) *Group

NewGroup creates a route group.

func (*Group) Any

func (group *Group) Any(path string, handler Handler) *Route

Any registers a route for common HTTP methods.

func (*Group) Delete

func (group *Group) Delete(path string, handler Handler) *Route

Delete registers a DELETE route.

func (*Group) Deprecated

func (group *Group) Deprecated(value ...bool) *Group

Deprecated marks group routes as deprecated.

func (*Group) Description

func (group *Group) Description(description string) *Group

Description sets group OpenAPI description metadata.

func (*Group) Doc

func (group *Group) Doc(names ...string) *Group

Doc sets OpenAPI document domains for the group.

func (*Group) Envelope

func (group *Group) Envelope(envelope Envelope) *Group

Envelope sets the group response envelope.

func (*Group) Error

func (group *Group) Error(renderer ErrorRenderer) *Group

Error sets the group error renderer.

func (*Group) Get

func (group *Group) Get(path string, handler Handler) *Route

Get registers a GET route.

func (*Group) Group

func (group *Group) Group(prefix string, fn ...func(*Group)) *Group

Group creates a nested group.

func (*Group) Handle

func (group *Group) Handle(method string, path string, handler Handler) *Route

Handle registers a route by method.

func (*Group) Head

func (group *Group) Head(path string, handler Handler) *Route

Head registers a HEAD route.

func (*Group) Meta

func (group *Group) Meta(key string, value any) *Group

Meta sets group metadata for child routes.

func (*Group) Mount

func (group *Group) Mount(register func(*Group)) *Group

Mount mounts route registrations into the group.

func (*Group) Name

func (group *Group) Name(name string) *Group

Name sets the group name prefix metadata.

func (*Group) OnError

func (group *Group) OnError(handler ErrorHandler) *Group

OnError sets the group error handler.

func (*Group) OptionalAuth

func (group *Group) OptionalAuth() *Group

OptionalAuth marks group routes as optionally authenticated.

func (*Group) Options

func (group *Group) Options(path string, handler Handler) *Route

Options registers an OPTIONS route.

func (*Group) Patch

func (group *Group) Patch(path string, handler Handler) *Route

Patch registers a PATCH route.

func (*Group) Post

func (group *Group) Post(path string, handler Handler) *Route

Post registers a POST route.

func (*Group) Put

func (group *Group) Put(path string, handler Handler) *Route

Put registers a PUT route.

func (*Group) Raw

func (group *Group) Raw() *Group

Raw disables response envelope for the group.

func (*Group) Registry

func (group *Group) Registry() *Registry

Registry returns the route registry that owns the group.

func (*Group) RouteGroup

func (group *Group) RouteGroup() *Group

RouteGroup returns the group itself.

func (*Group) Security

func (group *Group) Security(security ...Security) *Group

Security sets group OpenAPI security metadata.

func (*Group) SkipAuth

func (group *Group) SkipAuth() *Group

SkipAuth marks group routes as not requiring authentication.

func (*Group) SkipDoc

func (group *Group) SkipDoc() *Group

SkipDoc excludes the group and children from OpenAPI documents.

func (*Group) SkipPermission

func (group *Group) SkipPermission() *Group

SkipPermission marks group routes as not requiring permission checks.

func (*Group) Summary

func (group *Group) Summary(summary string) *Group

Summary sets group OpenAPI summary metadata.

func (*Group) Tags

func (group *Group) Tags(tags ...string) *Group

Tags sets group OpenAPI tags metadata.

func (*Group) Use

func (group *Group) Use(middlewares ...Middleware) *Group

Use appends group middlewares.

func (*Group) ViewDomain

func (group *Group) ViewDomain(name string) *Group

ViewDomain sets the default view domain for routes registered in this group.

type HTMLErrorRenderer

type HTMLErrorRenderer struct{}

HTMLErrorRenderer renders HTML errors.

func (HTMLErrorRenderer) RenderError

func (HTMLErrorRenderer) RenderError(ctx *Context, err error) error

RenderError renders an HTML error.

type HTTPError

type HTTPError struct {
	Status  int
	Code    string
	Message string
	Params  core.Map
	Cause   error
	// contains filtered or unexported fields
}

HTTPError is a route-layer HTTP error.

func (*HTTPError) Error

func (err *HTTPError) Error() string

Error returns the error message.

func (*HTTPError) ErrorCode

func (err *HTTPError) ErrorCode() string

ErrorCode returns the standard error code.

func (*HTTPError) ErrorMessage

func (err *HTTPError) ErrorMessage() string

ErrorMessage returns the public error message.

func (*HTTPError) ErrorParams

func (err *HTTPError) ErrorParams() core.Map

ErrorParams returns error parameters.

func (*HTTPError) ErrorStatus

func (err *HTTPError) ErrorStatus() int

ErrorStatus returns the HTTP status.

func (*HTTPError) Source

func (err *HTTPError) Source() string

Source returns the top source frame captured when this HTTP error was created.

func (*HTTPError) Stack

func (err *HTTPError) Stack() []runtime.Frame

Stack returns captured source frames.

func (*HTTPError) Unwrap

func (err *HTTPError) Unwrap() error

Unwrap returns the cause error.

type Handler

type Handler func(*Context) error

Handler handles a Runa HTTP request.

type InputValidator

type InputValidator interface {
	Validate(*validate.Validator)
}

InputValidator is implemented by inputs that define validation rules.

type JSONErrorRenderer

type JSONErrorRenderer struct{}

JSONErrorRenderer renders JSON errors.

func (JSONErrorRenderer) RenderError

func (JSONErrorRenderer) RenderError(ctx *Context, err error) error

RenderError renders a JSON error.

type Lang

type Lang struct {
	Default string
	Sources []LangSource
}

Lang configures request language resolution.

type LangSource

type LangSource interface {
	Resolve(*http.Request) string
}

LangSource resolves a language from an HTTP request.

type LangSourceFunc

type LangSourceFunc func(*http.Request) string

LangSourceFunc adapts a function to LangSource.

func (LangSourceFunc) Resolve

func (fn LangSourceFunc) Resolve(request *http.Request) string

Resolve resolves the language.

type LoggerProvider

type LoggerProvider interface {
	Get(name string) *slog.Logger
}

LoggerProvider returns named loggers without coupling route to a log package.

type Middleware

type Middleware func(Handler) Handler

Middleware wraps a route handler.

type NegotiatedErrorRenderer

type NegotiatedErrorRenderer struct{}

NegotiatedErrorRenderer renders errors based on Accept header.

func (NegotiatedErrorRenderer) RenderError

func (NegotiatedErrorRenderer) RenderError(ctx *Context, err error) error

RenderError renders an error based on Accept header.

type ProviderOption

type ProviderOption func(*routeProvider)

ProviderOption configures the route provider.

func Addr

func Addr(addr string) ProviderOption

Addr registers an HTTP host bound to addr.

func Server

func Server(config ServerConfig) ProviderOption

Server registers an HTTP host for the route registry.

func UseRegistry

func UseRegistry(registry *Registry) ProviderOption

UseRegistry uses an existing route registry.

type Registry

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

Registry stores routes and builds router runtimes.

func Default

func Default() *Registry

Default returns the process-wide default route registry installed by Provider.

func New

func New() *Registry

New creates a registry.

func SetDefault

func SetDefault(registry *Registry) *Registry

SetDefault sets the process-wide default route registry.

func (*Registry) Any

func (registry *Registry) Any(path string, handler Handler) *Route

func (*Registry) Build

func (registry *Registry) Build() (http.Handler, error)

Build builds the router handler.

func (*Registry) Config

func (registry *Registry) Config(store *config.Store)

Config sets the app config store.

func (*Registry) ConfigDef

func (registry *Registry) ConfigDef() *config.Store

ConfigDef returns the app config store.

func (*Registry) Delete

func (registry *Registry) Delete(path string, handler Handler) *Route

func (*Registry) Domain

func (registry *Registry) Domain(name string, prefix string, fn ...func(*Group)) *Group

Domain registers a named route domain.

func (*Registry) Envelope

func (registry *Registry) Envelope(envelope Envelope)

Envelope sets the app-level response envelope.

func (*Registry) EnvelopeDef

func (registry *Registry) EnvelopeDef() Envelope

EnvelopeDef returns the app-level response envelope.

func (*Registry) Error

func (registry *Registry) Error(renderer ErrorRenderer)

Error sets the app-level error renderer.

func (*Registry) ErrorPipeline

func (registry *Registry) ErrorPipeline() ErrorPipeline

ErrorPipeline returns the app-level error pipeline.

func (*Registry) Get

func (registry *Registry) Get(path string, handler Handler) *Route

func (*Registry) GetDomain

func (registry *Registry) GetDomain(name string) *Group

GetDomain returns a named route domain.

func (*Registry) GetGroup

func (registry *Registry) GetGroup(name string) *Group

GetGroup returns a named route group.

func (*Registry) Group

func (registry *Registry) Group(prefix string, fn ...func(*Group)) *Group

Group creates a route group from the root group.

func (*Registry) Handler

func (registry *Registry) Handler() http.Handler

Handler returns the built HTTP handler.

func (*Registry) Head

func (registry *Registry) Head(path string, handler Handler) *Route

func (*Registry) Lang

func (registry *Registry) Lang(config Lang)

Lang configures request language resolution.

func (*Registry) LangConfig

func (registry *Registry) LangConfig() Lang

LangConfig returns request language resolution config.

func (*Registry) MountDomain

func (registry *Registry) MountDomain(name string, fn func(*Group))

MountDomain mounts routes into a named route domain, resolving missing domains later.

func (*Registry) MountGroup

func (registry *Registry) MountGroup(name string, fn func(*Group))

MountGroup mounts routes into a named route group, resolving missing groups later.

func (*Registry) OnError

func (registry *Registry) OnError(handler ErrorHandler)

OnError sets the app-level error handler.

func (*Registry) Options

func (registry *Registry) Options(path string, handler Handler) *Route

func (*Registry) Patch

func (registry *Registry) Patch(path string, handler Handler) *Route

func (*Registry) PendingError

func (registry *Registry) PendingError() error

PendingError returns route registration errors.

func (*Registry) Post

func (registry *Registry) Post(path string, handler Handler) *Route

func (*Registry) Put

func (registry *Registry) Put(path string, handler Handler) *Route

func (*Registry) Register

func (registry *Registry) Register(route *Route) *Route

Register registers or replaces a route by method and path.

func (*Registry) RegisterDomain

func (registry *Registry) RegisterDomain(name string, group *Group) error

RegisterDomain registers a named route domain.

func (*Registry) RegisterGroup

func (registry *Registry) RegisterGroup(name string, group *Group)

RegisterGroup registers a named route group.

func (*Registry) ResolveMounts

func (registry *Registry) ResolveMounts() error

ResolveMounts resolves deferred mounts.

func (*Registry) RouteGroup

func (registry *Registry) RouteGroup() *Group

RouteGroup returns the root route group.

func (*Registry) Routes

func (registry *Registry) Routes() []*Route

Routes returns route snapshots in registration order.

func (*Registry) Server

func (registry *Registry) Server(config ServerConfig) *host.HTTPServer

Server creates an HTTP host unit backed by this route registry.

func (*Registry) Service

func (registry *Registry) Service(service any, name ...string)

Service binds an app-scoped service into route contexts.

func (*Registry) Services

func (registry *Registry) Services() map[string]any

Services returns a copy of app-scoped route services.

func (*Registry) Translator

func (registry *Registry) Translator(translator Translator)

Translator sets the app-level translator.

func (*Registry) TranslatorDef

func (registry *Registry) TranslatorDef() Translator

TranslatorDef returns the app-level translator.

func (*Registry) Use

func (registry *Registry) Use(middlewares ...Middleware) *Registry

Use appends root group middlewares.

type Renderer

type Renderer interface {
	RenderString(ctx interface{ Context() context.Context }, domain string, name string, data any) (string, error)
}

Renderer renders templates without coupling route to a view package.

type Route

type Route struct {
	Method          string
	Path            string
	FullPath        string
	Handler         Handler
	Middlewares     []Middleware
	MetaData        core.Map
	RouteName       string
	SummaryText     string
	DescriptionText string
	TagList         []string
	SecurityList    []Security
	DeprecatedFlag  bool
	DocNames        []string
	SkipDocument    bool
	SchemaDef       *SchemaInfo
	Errors          ErrorPipeline
	EnvelopeDef     Envelope
	RawResponse     bool
	SuccessStatus   int
	ViewDomainName  string
	// contains filtered or unexported fields
}

Route stores route metadata and handler.

func Any

func Any[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Any registers a typed route for common HTTP methods.

func Delete

func Delete[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Delete registers a typed DELETE route.

func Get

func Get[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Get registers a typed GET route.

func Head[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Head registers a typed HEAD route.

func Options

func Options[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Options registers a typed OPTIONS route.

func Patch

func Patch[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Patch registers a typed PATCH route.

func Post

func Post[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Post registers a typed POST route.

func Put

func Put[In any, Out any](target Target, path string, handler TypedHandler[In, Out]) *Route

Put registers a typed PUT route.

func Routes

func Routes() []*Route

Routes returns registered routes from the default route registry.

func (*Route) Deprecated

func (route *Route) Deprecated(value ...bool) *Route

Deprecated marks the route as deprecated.

func (*Route) Description

func (route *Route) Description(description string) *Route

Description sets route OpenAPI description metadata.

func (*Route) Doc

func (route *Route) Doc(names ...string) *Route

Doc sets OpenAPI document domains for this route.

func (*Route) Envelope

func (route *Route) Envelope(envelope Envelope) *Route

Envelope sets the route response envelope.

func (*Route) Error

func (route *Route) Error(renderer ErrorRenderer) *Route

Error sets the route error renderer.

func (*Route) Meta

func (route *Route) Meta(key string, value any) *Route

Meta sets route metadata.

func (*Route) Name

func (route *Route) Name(name string) *Route

Name sets the route name.

func (*Route) OnError

func (route *Route) OnError(handler ErrorHandler) *Route

OnError sets the route error handler.

func (*Route) OptionalAuth

func (route *Route) OptionalAuth() *Route

OptionalAuth marks this route as optionally authenticated.

func (*Route) Raw

func (route *Route) Raw() *Route

Raw disables response envelope for the route.

func (*Route) RouteID

func (route *Route) RouteID() string

RouteID returns the full route name used by permissions.

func (*Route) Schema

func (route *Route) Schema(schema SchemaInfo) *Route

Schema sets OpenAPI-neutral route schema metadata.

func (*Route) Security

func (route *Route) Security(security ...string) *Route

Security sets route OpenAPI security metadata.

func (*Route) SkipAuth

func (route *Route) SkipAuth() *Route

SkipAuth marks this route as not requiring authentication.

func (*Route) SkipDoc

func (route *Route) SkipDoc() *Route

SkipDoc excludes this route from OpenAPI documents.

func (*Route) SkipPermission

func (route *Route) SkipPermission() *Route

SkipPermission marks this route as not requiring permission checks.

func (*Route) Status

func (route *Route) Status(code int) *Route

Status sets the default success status for typed output.

func (*Route) Summary

func (route *Route) Summary(summary string) *Route

Summary sets route OpenAPI summary metadata.

func (*Route) Tags

func (route *Route) Tags(tags ...string) *Route

Tags sets route OpenAPI tags metadata.

func (*Route) Use

func (route *Route) Use(middlewares ...Middleware) *Route

Use appends route middlewares.

func (*Route) ViewDomain

func (route *Route) ViewDomain(name string) *Route

ViewDomain sets the default view domain for this route.

type SchemaInfo

type SchemaInfo struct {
	InputFields         []validate.FieldSchema
	RequestBody         *TypeSchema
	RequestContentType  string
	Response            *TypeSchema
	ResponseContentType string
}

SchemaInfo stores OpenAPI-neutral route schema metadata.

func TypedSchema

func TypedSchema[Input any, Output any]() SchemaInfo

TypedSchema builds route schema metadata from typed route generics.

type Security

type Security = string

Security names an OpenAPI security scheme.

type ServerConfig

type ServerConfig struct {
	Name            string
	Addr            string
	ReadTimeout     time.Duration
	WriteTimeout    time.Duration
	IdleTimeout     time.Duration
	ShutdownTimeout time.Duration
}

ServerConfig configures a route HTTP server.

type StatusRecorder

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

StatusRecorder records response status while proxying writes.

func NewStatusRecorder

func NewStatusRecorder(writer http.ResponseWriter) *StatusRecorder

NewStatusRecorder creates a response status recorder.

func (*StatusRecorder) Header

func (recorder *StatusRecorder) Header() http.Header

Header returns the proxied response headers.

func (*StatusRecorder) Status

func (recorder *StatusRecorder) Status() int

Status returns the recorded status code.

func (*StatusRecorder) Unwrap

func (recorder *StatusRecorder) Unwrap() http.ResponseWriter

Unwrap returns the underlying response writer.

func (*StatusRecorder) Write

func (recorder *StatusRecorder) Write(body []byte) (int, error)

Write writes response body.

func (*StatusRecorder) WriteHeader

func (recorder *StatusRecorder) WriteHeader(status int)

WriteHeader writes and records status code.

func (*StatusRecorder) Written

func (recorder *StatusRecorder) Written() bool

Written reports whether a status has been written.

type Target

type Target interface {
	RouteGroup() *Group
}

Target is implemented by route registration targets.

type TextErrorRenderer

type TextErrorRenderer struct{}

TextErrorRenderer renders plain text errors.

func (TextErrorRenderer) RenderError

func (TextErrorRenderer) RenderError(ctx *Context, err error) error

RenderError renders a plain text error.

type Translator

type Translator interface {
	Translate(*Context, string, string, core.Map) string
}

Translator translates messages for the current request.

type TranslatorFunc

type TranslatorFunc func(*Context, string, string, core.Map) string

TranslatorFunc adapts a function to Translator.

func (TranslatorFunc) Translate

func (fn TranslatorFunc) Translate(ctx *Context, currentLang string, message string, params core.Map) string

Translate translates a message.

type TypeSchema

type TypeSchema struct {
	Type        string                 `json:"type,omitempty"`
	Format      string                 `json:"format,omitempty"`
	Description string                 `json:"description,omitempty"`
	Default     any                    `json:"default,omitempty"`
	Required    []string               `json:"required,omitempty"`
	Nullable    bool                   `json:"nullable,omitempty"`
	Properties  map[string]*TypeSchema `json:"properties,omitempty"`
	Items       *TypeSchema            `json:"items,omitempty"`
	Additional  any                    `json:"additionalProperties,omitempty"`
	Ref         string                 `json:"$ref,omitempty"`
}

TypeSchema stores a minimal JSON-schema-like description.

func OutputSchema

func OutputSchema(output any) *TypeSchema

OutputSchema builds a response schema from an output value/type.

func SchemaOf

func SchemaOf(value any) *TypeSchema

SchemaOf builds a schema from a Go value or reflect.Type.

type TypedHandler

type TypedHandler[Input any, Output any] func(*Context, *Input) (*Output, error)

TypedHandler handles a typed request.

type XMLErrorRenderer

type XMLErrorRenderer struct{}

XMLErrorRenderer renders XML errors.

func (XMLErrorRenderer) RenderError

func (XMLErrorRenderer) RenderError(ctx *Context, err error) error

RenderError renders an XML error.

Jump to

Keyboard shortcuts

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