Documentation
¶
Index ¶
- Constants
- func GetSession(r *http.Request) (*contracts.Session, bool)
- func MetricsHandler(p *MetricsProvider) http.HandlerFunc
- type MetricsProvider
- type RoutePermission
- type Server
- func (s *Server) AddPublicPath(path string)
- func (s *Server) Drain(ctx context.Context) error
- func (s *Server) Handle(pattern string, handler http.Handler)
- func (s *Server) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (s *Server) RouteRequire(pattern, action, resource string)
- func (s *Server) SetAuditLogger(a contracts.AuditLogger)
- func (s *Server) SetAuthFunc(fn func(r *http.Request) (*contracts.Session, error))
- func (s *Server) SetAuthorizer(a contracts.Authorizer)
- func (s *Server) SetCSP(header string)
- func (s *Server) SetHealthChecker(fn func() map[string]error)
- func (s *Server) SetNodeID(id string)
- func (s *Server) SetRateLimiter(rl contracts.RateLimiterProvider)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start() error
Constants ¶
const SessionKey contextKey = "session"
SessionKey is the context key for storing the authenticated session.
Variables ¶
This section is empty.
Functions ¶
func GetSession ¶
GetSession retrieves the authenticated session from the request context.
func MetricsHandler ¶ added in v0.4.0
func MetricsHandler(p *MetricsProvider) http.HandlerFunc
MetricsHandler returns an http.HandlerFunc that emits Prometheus-format metrics. No external dependency — generates text/plain manually.
Enable via MUXCORE_METRICS_ENABLE=true. The endpoint is registered at /metrics.
Types ¶
type MetricsProvider ¶ added in v0.4.0
type MetricsProvider struct {
// DroppedEvents returns total events dropped by the event bus.
DroppedEvents func() int64
// ActiveSubscribers returns total active event subscriptions.
ActiveSubscribers func() int
// ConnPoolSize returns the number of pooled gRPC connections.
ConnPoolSize func() int
// RegistryModuleCount returns total registered modules.
RegistryModuleCount func() int
// LeaderTerm returns the current cluster election term.
LeaderTerm func() uint64
// IsLeader reports whether this node is the cluster leader.
IsLeader func() bool
}
MetricsProvider supplies runtime metrics for the /metrics endpoint. Each field is a function that returns the current value — called on every scrape so the response is always fresh.
type RoutePermission ¶ added in v0.4.0
RoutePermission describes the permission required to access a route.
type Server ¶
type Server struct {
AuthFunc func(r *http.Request) (*contracts.Session, error)
// contains filtered or unexported fields
}
func (*Server) AddPublicPath ¶ added in v0.4.0
AddPublicPath adds a path that should skip authentication entirely. Requests to public paths are not required to carry a valid session.
func (*Server) Drain ¶ added in v0.4.0
Drain signals the HTTP server to stop accepting new connections and waits for in-flight requests to complete within the given context deadline. After Drain returns, no new requests will be processed. Call Shutdown afterward for final cleanup.
Typical shutdown sequence:
- srv.Drain(drainCtx) — stop new connections, drain in-flight
- grpcSrv.GracefulStop() — drain gRPC
- modMgr.StopAll(...) — stop modules
- srv.Shutdown(ctx) — release remaining HTTP resources
func (*Server) HandleFunc ¶
HandleFunc registers a handler function for the given pattern.
func (*Server) RouteRequire ¶ added in v0.4.0
RouteRequire registers a permission requirement for a specific route. The route must match an HTTP path pattern registered with Handle/HandleFunc. The authorizer's Can() method will be called with the given action and resource after authentication for all requests to this route.
func (*Server) SetAuditLogger ¶ added in v0.4.0
func (s *Server) SetAuditLogger(a contracts.AuditLogger)
SetAuditLogger sets the audit logger for recording authenticated requests.
func (*Server) SetAuthFunc ¶
SetAuthFunc sets the authentication function for the middleware chain.
func (*Server) SetAuthorizer ¶ added in v0.4.0
func (s *Server) SetAuthorizer(a contracts.Authorizer)
SetAuthorizer sets the authorizer for permission checks in the middleware chain.
func (*Server) SetCSP ¶ added in v0.4.0
SetRateLimiter sets the rate limiter module for the middleware chain. SetCSP configures the Content-Security-Policy header sent on all responses. The default is restrictive: "default-src 'none'; frame-ancestors 'none'". Modules that serve HTML content (e.g. admin UI) must call this to set appropriate script-src, style-src, connect-src, and img-src directives.
func (*Server) SetHealthChecker ¶
SetHealthChecker sets a function that returns per-module health status.
func (*Server) SetRateLimiter ¶ added in v0.2.0
func (s *Server) SetRateLimiter(rl contracts.RateLimiterProvider)