Documentation
¶
Overview ¶
Package api implements the HTTP API server for Resin.
Index ¶
- func AuthMiddleware(adminToken string, next http.Handler) http.Handler
- func DecodeBody(r *http.Request, v interface{}) error
- func HandleCleanupSubscriptionCircuitOpenNodes(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleCreatePlatform(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleCreateSubscription(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleDeleteAllLeases(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleDeleteLease(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleDeletePlatform(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleDeleteRule(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleDeleteSubscription(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGeoIPLookup(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGeoIPLookupPost(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGeoIPStatus(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGeoIPUpdate(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGetLease(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGetNode(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGetPlatform(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleGetRequestLog(repo *requestlog.Repo) http.Handler
- func HandleGetRequestLogPayloads(repo *requestlog.Repo) http.Handler
- func HandleGetSubscription(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleHealthz() http.HandlerFunc
- func HandleHistoryAccessLatency(mgr *metrics.Manager) http.Handler
- func HandleHistoryLeaseLifetime(mgr *metrics.Manager) http.Handler
- func HandleHistoryNodePool(mgr *metrics.Manager) http.Handler
- func HandleHistoryProbes(mgr *metrics.Manager) http.Handler
- func HandleHistoryRequests(mgr *metrics.Manager) http.Handler
- func HandleHistoryTraffic(mgr *metrics.Manager) http.Handler
- func HandleIPLoad(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleListLeases(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleListNodes(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleListPlatforms(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleListRequestLogs(repo *requestlog.Repo) http.Handler
- func HandleListRules(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleListSubscriptions(cp *service.ControlPlaneService) http.HandlerFunc
- func HandlePatchSystemConfig(cp *service.ControlPlaneService) http.HandlerFunc
- func HandlePreviewFilter(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleProbeEgress(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleProbeLatency(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleRealtimeConnections(mgr *metrics.Manager) http.Handler
- func HandleRealtimeLeases(mgr *metrics.Manager) http.Handler
- func HandleRealtimeThroughput(mgr *metrics.Manager) http.Handler
- func HandleRebuildPlatform(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleRefreshSubscription(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleResetPlatform(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleResolveRule(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleSnapshotNodeLatencyDistribution(mgr *metrics.Manager) http.Handler
- func HandleSnapshotNodePool(mgr *metrics.Manager) http.Handler
- func HandleSnapshotPlatformNodePool(mgr *metrics.Manager) http.Handler
- func HandleSystemConfig(runtimeCfg *atomic.Pointer[config.RuntimeConfig]) http.HandlerFunc
- func HandleSystemDefaultConfig() http.HandlerFunc
- func HandleSystemEnvConfig(envCfg *config.EnvConfig) http.HandlerFunc
- func HandleSystemInfo(info service.SystemInfo) http.HandlerFunc
- func HandleUpdatePlatform(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleUpdateSubscription(cp *service.ControlPlaneService) http.HandlerFunc
- func HandleUpsertRule(cp *service.ControlPlaneService) http.HandlerFunc
- func NewTokenActionHandler(proxyToken string, cp *service.ControlPlaneService, apiMaxBodyBytes int64) http.Handler
- func PaginateSlice[T any](items []T, p Pagination) []T
- func ParseBoolQuery(r *http.Request, key string) (*bool, error)
- func PathParam(r *http.Request, name string) string
- func RequestBodyLimitMiddleware(maxBytes int64, next http.Handler) http.Handler
- func SortSlice[T any](items []T, sort Sorting, keyFn func(T) string)
- func ValidateUUID(s string) bool
- func WriteError(w http.ResponseWriter, status int, code, message string)
- func WriteJSON(w http.ResponseWriter, status int, data any)
- func WritePage[T any](w http.ResponseWriter, status int, allItems []T, p Pagination)
- type ErrorDetail
- type ErrorResponse
- type PageResponse
- type Pagination
- type Server
- type Sorting
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware returns an http.Handler that validates the Bearer token in the Authorization header against the expected admin token. If validation fails, it returns 401 Unauthorized with a JSON error body.
func DecodeBody ¶
DecodeBody decodes the JSON request body into v, rejecting unknown fields.
func HandleCleanupSubscriptionCircuitOpenNodes ¶
func HandleCleanupSubscriptionCircuitOpenNodes(cp *service.ControlPlaneService) http.HandlerFunc
HandleCleanupSubscriptionCircuitOpenNodes returns a handler for POST /api/v1/subscriptions/{id}/actions/cleanup-circuit-open-nodes.
func HandleCreatePlatform ¶
func HandleCreatePlatform(cp *service.ControlPlaneService) http.HandlerFunc
HandleCreatePlatform returns a handler for POST /api/v1/platforms.
func HandleCreateSubscription ¶
func HandleCreateSubscription(cp *service.ControlPlaneService) http.HandlerFunc
HandleCreateSubscription returns a handler for POST /api/v1/subscriptions.
func HandleDeleteAllLeases ¶
func HandleDeleteAllLeases(cp *service.ControlPlaneService) http.HandlerFunc
HandleDeleteAllLeases returns a handler for DELETE /api/v1/platforms/{id}/leases.
func HandleDeleteLease ¶
func HandleDeleteLease(cp *service.ControlPlaneService) http.HandlerFunc
HandleDeleteLease returns a handler for DELETE /api/v1/platforms/{id}/leases/{account}.
func HandleDeletePlatform ¶
func HandleDeletePlatform(cp *service.ControlPlaneService) http.HandlerFunc
HandleDeletePlatform returns a handler for DELETE /api/v1/platforms/{id}.
func HandleDeleteRule ¶
func HandleDeleteRule(cp *service.ControlPlaneService) http.HandlerFunc
HandleDeleteRule returns a handler for DELETE /api/v1/account-header-rules/{prefix}.
func HandleDeleteSubscription ¶
func HandleDeleteSubscription(cp *service.ControlPlaneService) http.HandlerFunc
HandleDeleteSubscription returns a handler for DELETE /api/v1/subscriptions/{id}.
func HandleGeoIPLookup ¶
func HandleGeoIPLookup(cp *service.ControlPlaneService) http.HandlerFunc
HandleGeoIPLookup returns a handler for GET /api/v1/geoip/lookup.
func HandleGeoIPLookupPost ¶
func HandleGeoIPLookupPost(cp *service.ControlPlaneService) http.HandlerFunc
HandleGeoIPLookupPost returns a handler for POST /api/v1/geoip/lookup (batch).
func HandleGeoIPStatus ¶
func HandleGeoIPStatus(cp *service.ControlPlaneService) http.HandlerFunc
HandleGeoIPStatus returns a handler for GET /api/v1/geoip/status.
func HandleGeoIPUpdate ¶
func HandleGeoIPUpdate(cp *service.ControlPlaneService) http.HandlerFunc
HandleGeoIPUpdate returns a handler for POST /api/v1/geoip/actions/update-now.
func HandleGetLease ¶
func HandleGetLease(cp *service.ControlPlaneService) http.HandlerFunc
HandleGetLease returns a handler for GET /api/v1/platforms/{id}/leases/{account}.
func HandleGetNode ¶
func HandleGetNode(cp *service.ControlPlaneService) http.HandlerFunc
HandleGetNode returns a handler for GET /api/v1/nodes/{hash}.
func HandleGetPlatform ¶
func HandleGetPlatform(cp *service.ControlPlaneService) http.HandlerFunc
HandleGetPlatform returns a handler for GET /api/v1/platforms/{id}.
func HandleGetRequestLog ¶
func HandleGetRequestLog(repo *requestlog.Repo) http.Handler
HandleGetRequestLog handles GET /api/v1/request-logs/{log_id}.
func HandleGetRequestLogPayloads ¶
func HandleGetRequestLogPayloads(repo *requestlog.Repo) http.Handler
HandleGetRequestLogPayloads handles GET /api/v1/request-logs/{log_id}/payloads. Returns base64-encoded payloads with truncation metadata.
func HandleGetSubscription ¶
func HandleGetSubscription(cp *service.ControlPlaneService) http.HandlerFunc
HandleGetSubscription returns a handler for GET /api/v1/subscriptions/{id}.
func HandleHealthz ¶
func HandleHealthz() http.HandlerFunc
HandleHealthz returns a handler for GET /healthz. No authentication is required.
func HandleHistoryAccessLatency ¶
HandleHistoryAccessLatency handles GET /api/v1/metrics/history/access-latency.
func HandleHistoryLeaseLifetime ¶
HandleHistoryLeaseLifetime handles GET /api/v1/metrics/history/lease-lifetime.
func HandleHistoryNodePool ¶
HandleHistoryNodePool handles GET /api/v1/metrics/history/node-pool.
func HandleHistoryProbes ¶
HandleHistoryProbes handles GET /api/v1/metrics/history/probes.
func HandleHistoryRequests ¶
HandleHistoryRequests handles GET /api/v1/metrics/history/requests.
func HandleHistoryTraffic ¶
HandleHistoryTraffic handles GET /api/v1/metrics/history/traffic.
func HandleIPLoad ¶
func HandleIPLoad(cp *service.ControlPlaneService) http.HandlerFunc
HandleIPLoad returns a handler for GET /api/v1/platforms/{id}/ip-load.
func HandleListLeases ¶
func HandleListLeases(cp *service.ControlPlaneService) http.HandlerFunc
HandleListLeases returns a handler for GET /api/v1/platforms/{id}/leases.
func HandleListNodes ¶
func HandleListNodes(cp *service.ControlPlaneService) http.HandlerFunc
HandleListNodes returns a handler for GET /api/v1/nodes.
func HandleListPlatforms ¶
func HandleListPlatforms(cp *service.ControlPlaneService) http.HandlerFunc
HandleListPlatforms returns a handler for GET /api/v1/platforms.
func HandleListRequestLogs ¶
func HandleListRequestLogs(repo *requestlog.Repo) http.Handler
HandleListRequestLogs handles GET /api/v1/request-logs. Query params: from, to (RFC3339Nano), limit, cursor, platform_id, platform_name, account, target_host, egress_ip, proxy_type, net_ok, http_status, fuzzy.
func HandleListRules ¶
func HandleListRules(cp *service.ControlPlaneService) http.HandlerFunc
HandleListRules returns a handler for GET /api/v1/account-header-rules.
func HandleListSubscriptions ¶
func HandleListSubscriptions(cp *service.ControlPlaneService) http.HandlerFunc
HandleListSubscriptions returns a handler for GET /api/v1/subscriptions.
func HandlePatchSystemConfig ¶
func HandlePatchSystemConfig(cp *service.ControlPlaneService) http.HandlerFunc
HandlePatchSystemConfig returns a handler for PATCH /api/v1/system/config.
func HandlePreviewFilter ¶
func HandlePreviewFilter(cp *service.ControlPlaneService) http.HandlerFunc
HandlePreviewFilter returns a handler for POST /api/v1/platforms/preview-filter.
func HandleProbeEgress ¶
func HandleProbeEgress(cp *service.ControlPlaneService) http.HandlerFunc
HandleProbeEgress returns a handler for POST /api/v1/nodes/{hash}/actions/probe-egress.
func HandleProbeLatency ¶
func HandleProbeLatency(cp *service.ControlPlaneService) http.HandlerFunc
HandleProbeLatency returns a handler for POST /api/v1/nodes/{hash}/actions/probe-latency.
func HandleRealtimeConnections ¶
HandleRealtimeConnections handles GET /api/v1/metrics/realtime/connections.
func HandleRealtimeLeases ¶
HandleRealtimeLeases handles GET /api/v1/metrics/realtime/leases.
func HandleRealtimeThroughput ¶
HandleRealtimeThroughput handles GET /api/v1/metrics/realtime/throughput.
func HandleRebuildPlatform ¶
func HandleRebuildPlatform(cp *service.ControlPlaneService) http.HandlerFunc
HandleRebuildPlatform returns a handler for POST /api/v1/platforms/{id}/actions/rebuild-routable-view.
func HandleRefreshSubscription ¶
func HandleRefreshSubscription(cp *service.ControlPlaneService) http.HandlerFunc
HandleRefreshSubscription returns a handler for POST /api/v1/subscriptions/{id}/actions/refresh.
func HandleResetPlatform ¶
func HandleResetPlatform(cp *service.ControlPlaneService) http.HandlerFunc
HandleResetPlatform returns a handler for POST /api/v1/platforms/{id}/actions/reset-to-default.
func HandleResolveRule ¶
func HandleResolveRule(cp *service.ControlPlaneService) http.HandlerFunc
HandleResolveRule returns a handler for POST /api/v1/account-header-rules:resolve.
func HandleSnapshotNodeLatencyDistribution ¶
HandleSnapshotNodeLatencyDistribution handles GET /api/v1/metrics/snapshots/node-latency-distribution. This returns a histogram of per-node authority-domain EWMA latencies, NOT the per-request access latency stored in the Collector.
func HandleSnapshotNodePool ¶
HandleSnapshotNodePool handles GET /api/v1/metrics/snapshots/node-pool.
func HandleSnapshotPlatformNodePool ¶
HandleSnapshotPlatformNodePool handles GET /api/v1/metrics/snapshots/platform-node-pool.
func HandleSystemConfig ¶
func HandleSystemConfig(runtimeCfg *atomic.Pointer[config.RuntimeConfig]) http.HandlerFunc
HandleSystemConfig returns a handler for GET /api/v1/system/config.
func HandleSystemDefaultConfig ¶
func HandleSystemDefaultConfig() http.HandlerFunc
HandleSystemDefaultConfig returns a handler for GET /api/v1/system/config/default.
func HandleSystemEnvConfig ¶
func HandleSystemEnvConfig(envCfg *config.EnvConfig) http.HandlerFunc
HandleSystemEnvConfig returns a handler for GET /api/v1/system/config/env.
func HandleSystemInfo ¶
func HandleSystemInfo(info service.SystemInfo) http.HandlerFunc
HandleSystemInfo returns a handler for GET /api/v1/system/info.
func HandleUpdatePlatform ¶
func HandleUpdatePlatform(cp *service.ControlPlaneService) http.HandlerFunc
HandleUpdatePlatform returns a handler for PATCH /api/v1/platforms/{id}.
func HandleUpdateSubscription ¶
func HandleUpdateSubscription(cp *service.ControlPlaneService) http.HandlerFunc
HandleUpdateSubscription returns a handler for PATCH /api/v1/subscriptions/{id}.
func HandleUpsertRule ¶
func HandleUpsertRule(cp *service.ControlPlaneService) http.HandlerFunc
HandleUpsertRule returns a handler for:
- PUT /api/v1/account-header-rules/{prefix...}
func NewTokenActionHandler ¶
func NewTokenActionHandler(proxyToken string, cp *service.ControlPlaneService, apiMaxBodyBytes int64) http.Handler
NewTokenActionHandler returns the handler for token-path actions.
func PaginateSlice ¶
func PaginateSlice[T any](items []T, p Pagination) []T
PaginateSlice applies limit/offset to a slice and returns the page.
func ParseBoolQuery ¶
ParseBoolQuery parses an optional boolean query parameter. Returns nil when the parameter is not present.
func PathParam ¶
PathParam extracts a named path parameter from the request URL. Works with Go 1.22+ ServeMux pattern matching (e.g. /platforms/{id}).
func RequestBodyLimitMiddleware ¶
RequestBodyLimitMiddleware enforces a max request body size for downstream handlers.
func SortSlice ¶
SortSlice sorts items in place by the given key extractor and sort order. keyFn must return a comparable string value for sorting.
func ValidateUUID ¶
ValidateUUID checks that s is a valid lowercase canonical UUID string.
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, code, message string)
WriteError writes a standard error response.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, data any)
WriteJSON writes a JSON response with the given status code.
func WritePage ¶
func WritePage[T any](w http.ResponseWriter, status int, allItems []T, p Pagination)
WritePage writes a paginated list response.
Types ¶
type ErrorDetail ¶
ErrorDetail contains the error code and human-readable message.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse is the standard error envelope.
type PageResponse ¶
type PageResponse[T any] struct { Items []T `json:"items"` Total int `json:"total"` Limit int `json:"limit"` Offset int `json:"offset"` }
PageResponse is the standard list envelope for paginated endpoints.
type Pagination ¶
Pagination holds parsed limit/offset values.
func ParsePagination ¶
func ParsePagination(r *http.Request) (Pagination, error)
ParsePagination reads limit and offset from query parameters.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps the HTTP server and mux for the Resin API.
func NewServer ¶
func NewServer( port int, adminToken string, systemInfo service.SystemInfo, runtimeCfg *atomic.Pointer[config.RuntimeConfig], envCfg *config.EnvConfig, cp *service.ControlPlaneService, apiMaxBodyBytes int64, requestlogRepo *requestlog.Repo, metricsManager *metrics.Manager, ) *Server
NewServer creates a new API server wired with all routes. cp may be nil if the control plane is not yet initialized.
func NewServerWithAddress ¶
func NewServerWithAddress( listenAddress string, port int, adminToken string, systemInfo service.SystemInfo, runtimeCfg *atomic.Pointer[config.RuntimeConfig], envCfg *config.EnvConfig, cp *service.ControlPlaneService, apiMaxBodyBytes int64, requestlogRepo *requestlog.Repo, metricsManager *metrics.Manager, ) *Server
NewServerWithAddress creates a new API server with an explicit listen address.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server. It blocks until the server stops.