api

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyRequestInfo  = common.ContextKeyAPIRequestInfo
	ContextKeyResponseInfo = common.ContextKeyAPIResponseInfo
	ContextKeyError        = common.ContextKeyAPIError
	ContextKeyCredential   = common.ContextKeyCredential
	ContextKeySession      = common.ContextKeySession
	ContextKeyTrace        = common.ContextKeyTrace
	ContextKeyDB           = common.ContextKeyDB
	ContextKeyLogger       = common.ContextKeyLogger

	CookiesKeySession = "JSESSIONID"

	HeaderKeyTrace        = "X-TRACE-ID"
	HeaderKeyFile         = "X-FILE-ID"
	HeaderKeyJob          = "X-JOB-ID"
	HeaderKeySession      = "X-SESSION-ID"
	HeaderKeyAPIToken     = "X-API-KEY"
	HeaderKeyAgentID      = "X-AGENT-ID"
	HeaderKeyClientCert   = "X-Ssl-Certificate"        // from nginx proxy_set_header $ssl_client_escaped_cert
	HeaderKeyClientVerify = "X-Ssl-Certificate-Verify" // from nginx proxy_set_header $ssl_client_verify

	QueryParamSession = "sid"
	QueryParamJob     = "job"

	LabelKeySession   = "session"
	LabelKeyNamespace = "organization"
	LabelKeyUsername  = "username"
)
View Source
const (
	MethodAny = "ANY"
	MethodWS  = "WS"
)
View Source
const ErrorSourceUnknown = "Unknown"

Variables

This section is empty.

Functions

func StatusCode

func StatusCode(err error) int

Types

type CORSConfig added in v0.6.1

type CORSConfig struct {
	AllowOrigins     []string `yaml:"allow_origins"`
	AllowMethods     []string `yaml:"allow_methods"`
	AllowHeaders     []string `yaml:"allow_headers"`
	AllowCredentials bool     `yaml:"allow_credentials"`
	MaxAge           int      `yaml:"max_age"`
}

CORSConfig is the policy block of the server's built-in cors middleware, written in YAML under "cors" in the server's middleware configs. Empty fields keep echo's permissive defaults. Unknown fields fail startup, and AllowCredentials requires explicit AllowOrigins - browsers reject credentials against a wildcard origin, so that combination never works and is refused.

type ClientTLS

type ClientTLS struct {
	CertBundle certutil.CertBundle
	AuthType   tls.ClientAuthType
}

func (*ClientTLS) AsConfig

func (ct *ClientTLS) AsConfig() *tls.Config

type Encoding added in v0.4.0

type Encoding string
const (
	EncodingDeflate Encoding = "deflate"
)

type Endpoint

type Endpoint struct {
	Protocol string
	Host     string
	Port     uint
	Path     string
}

func NewEndpoint

func NewEndpoint(address string) *Endpoint

func (*Endpoint) Address

func (e *Endpoint) Address() string

func (*Endpoint) String

func (e *Endpoint) String() string

type ErrorBody

type ErrorBody struct {
	Origin  error      `json:"-"`                // keep the original error to trace the stack
	Source  string     `json:"source,omitempty"` // source
	Status  int        `json:"status,omitempty"` // http status code
	Code    string     `json:"code,omitempty"`   // customized error code
	Kind    string     `json:"kind,omitempty"`   // error category
	Message string     `json:"message,omitempty"`
	Details labels.Set `json:"details,omitempty"`
}

func WrapError

func WrapError(err error, c echo.Context) *ErrorBody

func (*ErrorBody) Error

func (e *ErrorBody) Error() string

func (*ErrorBody) Format

func (e *ErrorBody) Format(f fmt.State, c rune)

type Middleware

type Middleware interface {
	common.Service
	// Func returns the middleware function for one attachment point. config is
	// the raw YAML written under the middleware's name, and nil when there is
	// none. Called once per attachment at registration time - and again on
	// restart, when routes are rebuilt - so per-route state lives in the
	// returned closure. An error fails registration; returning no function
	// and no error declines the attachment, and the server skips it.
	Func(config []byte) (func(echo.HandlerFunc) echo.HandlerFunc, error)
}

Middleware is one of the two extension points of the API server, the mirror image of Router: where a Router supplies its configuration to the framework, a Middleware receives configuration from it.

type RequestInfo

type RequestInfo struct {
	Server     string
	URI        string
	Method     string
	Path       string
	RawPath    string
	TraceID    string
	IP         string
	StartedAt  time.Time
	Permission string
	Poll       bool
}

RequestInfo is what the server's Info middleware resolves onto the request context for everything downstream. Route metadata declared in router.yaml - the permission, the poll flag - arrives flattened here; the parsed schema itself never leaves the server package.

type ResponseInfo

type ResponseInfo struct {
	Status  int
	Took    time.Duration
	Size    uint64
	TraceID string
	Error   *ErrorBody
}

type Router

type Router interface {
	common.Service
	Config() []byte
	Handlers() map[string]any // echo.HandlerFunc or WebSocketHandlerFunc
}

type ServerTLS

type ServerTLS struct {
	CertBundle  certutil.CertBundle
	AuthEnabled bool
}

func (*ServerTLS) AsConfig

func (st *ServerTLS) AsConfig() *tls.Config

type Stats

type Stats struct {
	RequestInfo
	ResponseInfo
}

Jump to

Keyboard shortcuts

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