api

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SessionKey contextKey = "session"

SessionKey is the context key for storing the authenticated session.

Variables

This section is empty.

Functions

func GetSession

func GetSession(r *http.Request) (*contracts.Session, bool)

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

type RoutePermission struct {
	Action   string
	Resource string
}

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 NewServer

func NewServer(addr, certFile, keyFile string) *Server

func (*Server) AddPublicPath added in v0.4.0

func (s *Server) AddPublicPath(path string)

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

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

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:

  1. srv.Drain(drainCtx) — stop new connections, drain in-flight
  2. grpcSrv.GracefulStop() — drain gRPC
  3. modMgr.StopAll(...) — stop modules
  4. srv.Shutdown(ctx) — release remaining HTTP resources

func (*Server) Handle

func (s *Server) Handle(pattern string, handler http.Handler)

Handle registers an http.Handler for the given pattern.

func (*Server) HandleFunc

func (s *Server) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers a handler function for the given pattern.

func (*Server) RouteRequire added in v0.4.0

func (s *Server) RouteRequire(pattern, action, resource string)

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

func (s *Server) SetAuthFunc(fn func(r *http.Request) (*contracts.Session, error))

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

func (s *Server) SetCSP(header string)

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

func (s *Server) SetHealthChecker(fn func() map[string]error)

SetHealthChecker sets a function that returns per-module health status.

func (*Server) SetNodeID added in v0.4.0

func (s *Server) SetNodeID(id string)

SetNodeID sets the node identifier for audit entries.

func (*Server) SetRateLimiter added in v0.2.0

func (s *Server) SetRateLimiter(rl contracts.RateLimiterProvider)

func (*Server) Shutdown

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

func (*Server) Start

func (s *Server) Start() error

Jump to

Keyboard shortcuts

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