server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLog added in v0.21.0

func AccessLog(log *slog.Logger) echo.MiddlewareFunc

AccessLog writes the one result record for each request: the access fields, and for a failed request the error fields of its attribution. It recovers a panic into an error with the stack of the panic, and answers an error that is still unanswered through the shell's HTTP error handler, so the record carries the status that was sent.

Install it directly after telemetry.EchoServer, so the record is logged with the request's span and every middleware below it is covered.

func NewHTTPErrorHandler added in v0.21.0

func NewHTTPErrorHandler(log *slog.Logger) echo.HTTPErrorHandler

NewHTTPErrorHandler renders every error a request ends with as a Problem. It does not log the error: the access log writes the one result record for the request. An HTTP shell installs it together with AccessLog.

Types

type Handler

type Handler interface {
	Register(e *echo.Echo)
}

type Problem added in v0.22.0

type Problem struct {
	Type      string            `json:"type" validate:"required"`
	Status    int               `json:"status" validate:"required"`
	Detail    string            `json:"detail" validate:"required"`
	Code      string            `json:"code" validate:"required"`
	Args      map[string]string `json:"args" validate:"required"`
	Fault     apperror.Fault    `json:"fault" validate:"required"`
	RequestID string            `json:"request_id,omitempty"`
	TraceID   string            `json:"trace_id,omitempty"`
}

Problem is the RFC 9457 body of an HTTP error response. Fault and TraceID are filled by the HTTP boundary: fault is its attribution of the error (client, server, dependency or canceled), which a client uses to choose generic copy for a code it does not know.

func ProblemFrom added in v0.22.0

func ProblemFrom(err error, requestID string) (Problem, bool)

ProblemFrom is the Problem for the outermost apperror on err, with the status and detail of its catalog entry. It reports false when err holds no apperror whose code is in the catalog.

type Server

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

func NewServer

func NewServer(log *slog.Logger, addr string, jwtSecret string,
	handlers ...Handler,
) *Server

func NewServerWithSessionValidator

func NewServerWithSessionValidator(log *slog.Logger, addr string, jwtSecret string,
	validateSession auth.UserSessionValidator, handlers ...Handler,
) *Server

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

type StreamError added in v0.22.0

type StreamError struct {
	Type   string            `json:"type" enums:"error"`
	Code   string            `json:"code"`
	Args   map[string]string `json:"args"`
	Detail string            `json:"detail"`
	// Message repeats Detail. A Web client recognizes an error event by it.
	Message   string         `json:"message"`
	Fault     apperror.Fault `json:"fault"`
	RequestID string         `json:"request_id,omitempty"`
}

StreamError is the error event of a stream that is already open: an SSE error frame or a WebSocket error frame. It carries the public error the HTTP error handler would answer with, and never the error's own text.

func NewStreamError added in v0.22.0

func NewStreamError(ctx context.Context, err error, requestID string) (StreamError, error)

NewStreamError is the error event for err, chosen by errs.Answer, and the error the event was rendered from. A handler that sends the event returns that error, so that the request's result record attributes it; it does not log it itself.

Jump to

Keyboard shortcuts

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