Documentation
¶
Index ¶
- Constants
- func SignalContext(parent context.Context) (context.Context, context.CancelFunc)
- type App
- type Check
- type ConnectOption
- type ConnectService
- type InitOption
- type Middleware
- type Route
- type RouteOption
- type Runtime
- func (r Runtime) ConnectClientOptions() ([]connect.ClientOption, error)
- func (r Runtime) ConnectHTTPClient(client ...*http.Client) *http.Client
- func (r Runtime) Context() context.Context
- func (r Runtime) HTTPClient(client ...*http.Client) *http.Client
- func (r Runtime) Logger() *slog.Logger
- func (r Runtime) NewService(opts ...ServiceOption) Service
- func (r Runtime) Shutdown(ctx context.Context) error
- func (r Runtime) TelemetryConfig() telemetry.Config
- type Service
- type ServiceOption
- func WithReflection() ServiceOption
- func WithServiceAddr(addr string) ServiceOption
- func WithServiceConnectOptions(options ...connect.HandlerOption) ServiceOption
- func WithServiceIdleTimeout(timeout time.Duration) ServiceOption
- func WithServiceInterceptors(interceptors ...connect.Interceptor) ServiceOption
- func WithServiceLivenessChecks(checks ...Check) ServiceOption
- func WithServiceLogger(logger *slog.Logger) ServiceOption
- func WithServiceMiddleware(middleware ...Middleware) ServiceOption
- func WithServiceReadinessChecks(checks ...Check) ServiceOption
- func WithServiceRoutes(routes ...Route) ServiceOption
- func WithServiceTLSConfig(cfg *tls.Config) ServiceOption
- func WithServiceTLSFiles(certFile, keyFile string) ServiceOption
- func WithServiceTelemetry(cfg telemetry.Config) ServiceOption
- func WithServiceTimeouts(readHeaderTimeout, shutdownTimeout time.Duration) ServiceOption
- func WithServices(services ...ConnectService) ServiceOption
Constants ¶
const ( // DefaultAddr is the default listen address for HTTP apps. DefaultAddr = httpserver.DefaultAddr // LivenessService is the Kubernetes gRPC health service label for liveness. LivenessService = httpserver.LivenessService // ReadinessService is the Kubernetes gRPC health service label for readiness. ReadinessService = httpserver.ReadinessService )
Variables ¶
This section is empty.
Functions ¶
func SignalContext ¶
SignalContext returns a context canceled on SIGINT or SIGTERM.
Types ¶
type App ¶
type App struct {
Addr string
Routes []Route
Connect []ConnectService
Reflection bool
LivenessChecks []Check
ReadinessChecks []Check
Interceptors []connect.Interceptor
ConnectOptions []connect.HandlerOption
Middleware []Middleware
Logger *slog.Logger
Telemetry telemetry.Config
ReadHeaderTimeout time.Duration
IdleTimeout time.Duration
ShutdownTimeout time.Duration
TLSConfig *tls.Config
TLSCertFile string
TLSKeyFile string
}
App is the shared assembly base used by Service. Prefer NewService for normal internal services.
type Check ¶
type Check = httpserver.Check
Check is a health dependency check.
func LivenessCheck ¶
LivenessCheck adapts fn into a liveness check.
type ConnectOption ¶
type ConnectOption func(*ConnectService)
ConnectOption customizes a Connect service.
func WithConnectMiddleware ¶
func WithConnectMiddleware(middleware ...Middleware) ConnectOption
WithConnectMiddleware adds HTTP middleware to a Connect service.
func WithConnectOptions ¶
func WithConnectOptions(options ...connect.HandlerOption) ConnectOption
WithConnectOptions adds Connect handler options to a Connect service.
func WithInterceptors ¶
func WithInterceptors(interceptors ...connect.Interceptor) ConnectOption
WithInterceptors adds Connect interceptors to a Connect service.
type ConnectService ¶
type ConnectService struct {
Name string
NewHandler func(...connect.HandlerOption) (string, http.Handler)
Interceptors []connect.Interceptor
ConnectOptions []connect.HandlerOption
Middleware []Middleware
}
ConnectService is a generated Connect service handler factory plus service specific options.
func Connect ¶
func Connect(name string, newHandler func(...connect.HandlerOption) (string, http.Handler), opts ...ConnectOption) ConnectService
Connect builds a Connect service registration.
func ConnectHandler ¶
func ConnectHandler[T any]( name string, newHandler func(T, ...connect.HandlerOption) (string, http.Handler), implementation T, opts ...ConnectOption, ) ConnectService
ConnectHandler builds a Connect service registration from a generated Connect handler constructor and service implementation.
type InitOption ¶
type InitOption func(*initConfig)
InitOption customizes process-level framework initialization.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) InitOption
WithHTTPClient sets the runtime's base outbound HTTP client.
func WithLogger ¶
func WithLogger(logger *slog.Logger) InitOption
WithLogger overrides the process default logger installed by Init.
func WithTelemetry ¶
func WithTelemetry(cfg telemetry.Config) InitOption
WithTelemetry overrides the default telemetry configuration for Init.
type Middleware ¶
type Middleware = httpmiddleware.Middleware
Middleware wraps an HTTP handler. The first middleware in a list is outermost.
type Route ¶
type Route struct {
Pattern string
Handler http.Handler
Middleware []Middleware
}
Route is a regular HTTP route.
type RouteOption ¶
type RouteOption func(*Route)
RouteOption customizes a route.
func WithMiddleware ¶
func WithMiddleware(middleware ...Middleware) RouteOption
WithMiddleware adds HTTP middleware to a route.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime holds process-level framework initialization.
func Init ¶
func Init(ctx context.Context, opts ...InitOption) (Runtime, error)
Init performs process-level framework initialization.
func (Runtime) ConnectClientOptions ¶
func (r Runtime) ConnectClientOptions() ([]connect.ClientOption, error)
ConnectClientOptions returns Connect client options for RPC telemetry.
func (Runtime) ConnectHTTPClient ¶
ConnectHTTPClient returns a runtime outbound client for generated Connect clients. Passing a client overrides the runtime base client for this call. Connect telemetry comes from ConnectClientOptions, so this does not wrap the transport with HTTP telemetry.
func (Runtime) Context ¶
Context returns the runtime context canceled on SIGINT, SIGTERM, parent cancellation, or Shutdown.
func (Runtime) HTTPClient ¶
HTTPClient returns a runtime outbound client whose transport emits HTTP telemetry. Passing a client overrides the runtime base client for this call.
func (Runtime) NewService ¶
func (r Runtime) NewService(opts ...ServiceOption) Service
NewService builds a Service using the runtime telemetry configuration.
func (Runtime) TelemetryConfig ¶
TelemetryConfig returns the runtime telemetry configuration.
type Service ¶
type Service struct {
Addr string
Connect []ConnectService
Routes []Route
Reflection bool
LivenessChecks []Check
ReadinessChecks []Check
Interceptors []connect.Interceptor
ConnectOptions []connect.HandlerOption
Middleware []Middleware
Logger *slog.Logger
Telemetry telemetry.Config
ReadHeaderTimeout time.Duration
IdleTimeout time.Duration
ShutdownTimeout time.Duration
TLSConfig *tls.Config
TLSCertFile string
TLSKeyFile string
}
Service is the normal shape for an internal Connect service.
func NewService ¶
func NewService(opts ...ServiceOption) Service
NewService builds an internal Connect service with framework defaults.
type ServiceOption ¶
type ServiceOption func(*Service)
ServiceOption customizes a Service.
func WithReflection ¶
func WithReflection() ServiceOption
WithReflection enables explicit Connect reflection.
func WithServiceAddr ¶
func WithServiceAddr(addr string) ServiceOption
WithServiceAddr overrides the default listen address.
func WithServiceConnectOptions ¶
func WithServiceConnectOptions(options ...connect.HandlerOption) ServiceOption
WithServiceConnectOptions adds common Connect handler options.
func WithServiceIdleTimeout ¶
func WithServiceIdleTimeout(timeout time.Duration) ServiceOption
WithServiceIdleTimeout overrides the server idle timeout.
func WithServiceInterceptors ¶
func WithServiceInterceptors(interceptors ...connect.Interceptor) ServiceOption
WithServiceInterceptors adds common Connect interceptors.
func WithServiceLivenessChecks ¶
func WithServiceLivenessChecks(checks ...Check) ServiceOption
WithServiceLivenessChecks adds liveness checks.
func WithServiceLogger ¶
func WithServiceLogger(logger *slog.Logger) ServiceOption
WithServiceLogger sets the service logger.
func WithServiceMiddleware ¶
func WithServiceMiddleware(middleware ...Middleware) ServiceOption
WithServiceMiddleware replaces the service HTTP middleware stack.
func WithServiceReadinessChecks ¶
func WithServiceReadinessChecks(checks ...Check) ServiceOption
WithServiceReadinessChecks adds readiness checks.
func WithServiceRoutes ¶
func WithServiceRoutes(routes ...Route) ServiceOption
WithServiceRoutes adds regular HTTP routes.
func WithServiceTLSConfig ¶
func WithServiceTLSConfig(cfg *tls.Config) ServiceOption
WithServiceTLSConfig enables TLS with an application-provided TLS config.
func WithServiceTLSFiles ¶
func WithServiceTLSFiles(certFile, keyFile string) ServiceOption
WithServiceTLSFiles enables TLS with certificate and private key files.
func WithServiceTelemetry ¶
func WithServiceTelemetry(cfg telemetry.Config) ServiceOption
WithServiceTelemetry overrides the service OpenTelemetry configuration.
func WithServiceTimeouts ¶
func WithServiceTimeouts(readHeaderTimeout, shutdownTimeout time.Duration) ServiceOption
WithServiceTimeouts overrides server timeouts.
func WithServices ¶
func WithServices(services ...ConnectService) ServiceOption
WithServices adds Connect services.