Documentation
¶
Overview ¶
Package runtime is the stdlib-only service runtime library.
Index ¶
- type Code
- type Config
- type Error
- func AlreadyExists(format string, args ...any) *Error
- func As(err error) (*Error, bool)
- func Internal(format string, args ...any) *Error
- func InvalidArgument(format string, args ...any) *Error
- func NotFound(format string, args ...any) *Error
- func PermissionDenied(format string, args ...any) *Error
- func Unavailable(format string, args ...any) *Error
- func Wrap(code Code, cause error, format string, args ...any) *Error
- type Interceptor
- type Invoker
- type Server
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// ShutdownTimeout bounds how long Run waits for transports to drain
// after the run context is canceled or a transport fails fatally.
// Zero means defaultShutdownTimeout (applied by New).
ShutdownTimeout time.Duration
// Logger receives lifecycle events. Nil means slog.Default() (applied
// by New).
Logger *slog.Logger
}
Config configures a Server's lifecycle.
type Error ¶
Error is the runtime error type returned by generated handlers and decoded by generated clients. Code and Message are serialized on the wire; err is unexported and never serialized — it exists only to preserve the causal chain for errors.Is/errors.As on the server side.
func AlreadyExists ¶
AlreadyExists builds an Error with CodeAlreadyExists.
func InvalidArgument ¶
InvalidArgument builds an Error with CodeInvalidArgument.
func PermissionDenied ¶
PermissionDenied builds an Error with CodePermissionDenied.
func Unavailable ¶
Unavailable builds an Error with CodeUnavailable.
func Wrap ¶
Wrap builds an Error with the given code and message, preserving cause for errors.Is/errors.As. The cause is never included in Error()'s output.
type Interceptor ¶
Interceptor wraps an Invoker to add cross-cutting behavior (logging, auth, tracing, etc.) around the call it wraps.
func Chain ¶
func Chain(interceptors ...Interceptor) Interceptor
Chain composes interceptors into a single Interceptor. The first interceptor passed is the outermost: its code before calling next runs first, and its code after calling next runs last. Chain() with no interceptors returns a pass-through Interceptor.
func LoggingInterceptor ¶
func LoggingInterceptor(logger *slog.Logger) Interceptor
LoggingInterceptor returns an Interceptor that emits exactly one structured log record per call, containing the RPC method, its duration, and (when present) the error it returned. The wrapped call's response and error are returned unchanged.
type Invoker ¶
Invoker is a single call in a transport-agnostic RPC pipeline. method identifies the target as "Service.Method", e.g. "Orders.GetOrder".
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server hosts one or more Transports and coordinates their lifecycle: starting them concurrently, watching for OS interrupt signals or a fatal transport error, and draining every transport gracefully on shutdown.
func New ¶
New builds a Server for the given transports. Zero-value fields in cfg are replaced by defaults: ShutdownTimeout defaults to 15s, Logger defaults to slog.Default().
func (*Server) Run ¶
Run starts every transport in its own goroutine and blocks until ctx is canceled, an OS interrupt/SIGTERM signal is received, or any transport's Start returns a fatal (non-nil) error. It then drains all transports within cfg.ShutdownTimeout and returns the first fatal error encountered, or nil on clean shutdown.
type Transport ¶
type Transport interface {
// Name identifies the transport for logging.
Name() string
// Start blocks until ctx is canceled or a fatal error occurs. A clean
// stop (ctx canceled, Shutdown called) returns nil; any non-nil return
// is treated as a fatal error that triggers shutdown of all
// transports.
Start(ctx context.Context) error
// Shutdown drains the transport gracefully, respecting ctx's deadline.
Shutdown(ctx context.Context) error
}
Transport hosts a service over a specific protocol (e.g. HTTP, gRPC). A Server coordinates the lifecycle of one or more Transports.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package httptransport hosts a service over net/http.
|
Package httptransport hosts a service over net/http. |