listener

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateInterceptor

func AuthenticateInterceptor(a auth.Authenticator, cls SchemeClassifier) connect.Interceptor

AuthenticateInterceptor runs the Authenticator against every request and attaches the resulting Principal to the context. Returns CodeUnauthenticated if authentication fails.

func AuthorizeInterceptor

func AuthorizeInterceptor(az auth.Authorizer, actions map[string]auth.Action) connect.Interceptor

AuthorizeInterceptor checks the principal in ctx against the action map. Procedures not in the map are allowed through unconditionally.

func MetricsInterceptor

func MetricsInterceptor(m *observability.Metrics) connect.Interceptor

MetricsInterceptor records per-procedure request count and latency via the gohome_api_* Prometheus metrics.

func RecoverInterceptor

func RecoverInterceptor() connect.Interceptor

RecoverInterceptor catches panics from downstream handlers and converts them to connect.CodeInternal errors, logging the stack trace.

func RequestIDInterceptor

func RequestIDInterceptor() connect.Interceptor

RequestIDInterceptor mints or echoes the X-Request-Id header and stores the value in the request context via observability.WithRequestID.

func SlogInterceptor

func SlogInterceptor() connect.Interceptor

SlogInterceptor logs each completed RPC with method, code, duration, and request-id.

func WithPeerCred

func WithPeerCred(ctx context.Context, c *auth.PeerCred) context.Context

WithPeerCred attaches the Unix peer credentials to ctx. Called by the UDS connection handler before the request is dispatched.

Types

type Config

type Config struct {
	UDSPath string
	UDSMode os.FileMode

	TCPBind string

	TLSCertFile string
	TLSKeyFile  string
}

type Deps

type Deps struct {
	HealthProbe    func() error
	ConnectRoutes  []Route
	WebhookHandler http.Handler
	MCPHandler     http.Handler // nil means /mcp is not served
	WidgetsHandler http.Handler // serves /widgets/ — mounted before the SPA catch-all
	WebHandler     http.Handler // SPA handler — mounted as catch-all
}

type Listener

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

func Build

func Build(cfg Config, deps Deps) (*Listener, error)

func (*Listener) Shutdown

func (l *Listener) Shutdown(ctx context.Context) error

func (*Listener) Start

func (l *Listener) Start(ctx context.Context) error

func (*Listener) TCPAddr

func (l *Listener) TCPAddr() net.Addr

type Route

type Route struct {
	Path    string
	Handler http.Handler
}

func BuildRoutes

func BuildRoutes(svc Services, interceptors ...connect.Interceptor) []Route

BuildRoutes returns the (path, handler) pairs to mount on the listener mux. NewXServiceHandler returns (string, http.Handler).

type SchemeClassifier

type SchemeClassifier interface {
	Classify(req connect.AnyRequest) (scheme string, isUDS bool)
}

SchemeClassifier classifies a request into an auth scheme and whether it arrived on the Unix-domain socket.

Jump to

Keyboard shortcuts

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