Documentation
¶
Index ¶
Constants ¶
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" )
const ( MethodAny = "ANY" MethodWS = "WS" )
const ErrorSourceUnknown = "Unknown"
Variables ¶
This section is empty.
Functions ¶
func PublicMessage ¶ added in v0.9.12
PublicMessage is what a response at status tells a client of err: the outermost message the server's own code wrote (errors.MessageOf), and nothing for a bare Category, which the response's kind names. Where the code wrote none, a 5xx says its status text, and a 4xx the text of the error it received - an echo error's message, a failed validation's fields (design/errors.md).
func SetContext ¶ added in v0.9.11
SetContext replaces c's request with one carrying ctx: how a middleware hands a value to everything below it, since echo keeps no context of its own and the request's is the one (design/request-context.md).
func StatusCode ¶
StatusCode is the status WrapError answers err with, for metrics and spans to agree with the committed response.
Types ¶
type ClientTLS ¶
type ClientTLS struct {
CertBundle certutil.CertBundle
RootCAs []*x509.Certificate
}
ClientTLS is the certificate a client presents, if any, and the CAs it verifies the server against - the system's when RootCAs is empty.
type Endpoint ¶
func NewEndpoint ¶
type ErrorBody ¶
type ErrorBody struct {
Origin error `json:"-"` // keep the original error to trace the stack
Source string `json:"source,omitempty"`
Status int `json:"status,omitempty"`
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 ¶
WrapError builds the response body for a handler's error. Status and Kind come from the category the error resolves to, through wrappers from any package: a context.Canceled or context.DeadlineExceeded is Canceled or DeadlineExceeded, a Combine of several reasons no wrapper declared is Combined, and an error without a category is Internal. Where no category was declared, an *echo.HTTPError in the chain - echo's own verdict on this request, a failed c.Bind's 400 among them - answers with its code, and no kind. An *ErrorBody returned as is is the handler's own answer and goes out unchanged; wrapped, it may be another service's, which is not honoured. Message is PublicMessage's; Origin keeps the whole chain for the log (design/errors.md).
func (*ErrorBody) Format ¶
Format follows xhanio/errors. %s, %v and %m print Error() and nothing else, so a body reads like any other error when printed or wrapped with fmt.Errorf("%w"), which renders its operand with %v. %+v adds the status, kind, code and details: "(404) NotFound: user u1 not found {code: X, details: k=v}". %q prints Error() quoted.
type Middleware ¶
type Middleware interface {
common.Service
// Func is called per attachment, again on every restart, so per-route state
// lives in the closure. enabled is the most specific boolean under the
// middleware's name (else the entry's presence); config is the most
// specific non-boolean YAML, resolved independently, nil when absent.
// An error fails registration; (nil, nil) declines the attachment.
Func(enabled bool, config []byte) (func(echo.HandlerFunc) echo.HandlerFunc, error)
}
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 set on the request context by the server's Info middleware.
type ResponseInfo ¶
type ServerTLS ¶
type ServerTLS struct {
CertBundle certutil.CertBundle
ClientCAs []*x509.Certificate // empty: no client certificate is asked for
}
ServerTLS is the server's certificate and the CAs a client certificate is verified against. One is asked for, not required: a listener serves users by session as well, and the route decides who must present one.
type Stats ¶
type Stats struct {
RequestInfo
ResponseInfo
}