Documentation
¶
Overview ¶
Package httpserver is the Gin HTTP layer: routes, JSON/error envelopes, API-key auth on mutating endpoints, and wiring to executor.Executor (business logic). List/read routes are public; POST/PUT/DELETE require Bearer API key.
Index ¶
- Constants
- func APIKeyAuth(secret string, log *zap.Logger) gin.HandlerFunc
- func NormalizeListLimit(n int) int
- func ParseListLimitQuery(s string) (int, error)
- func RegisterRoutes(r *gin.Engine, h *Handler, cfg *config.Config, log *zap.Logger)
- func SetAuthMode(c *gin.Context, mode AuthMode)
- func SignatureOrAPIKeyAuth(secret string, log *zap.Logger) gin.HandlerFunc
- func ZapLogger(log *zap.Logger) gin.HandlerFunc
- type AuthMode
- type ErrorResponse
- type Handler
- func (h *Handler) APIInfo(c *gin.Context)
- func (h *Handler) CreateChannel(c *gin.Context)
- func (h *Handler) CreatePlaylist(c *gin.Context)
- func (h *Handler) CreatePlaylistGroup(c *gin.Context)
- func (h *Handler) DeleteChannel(c *gin.Context)
- func (h *Handler) DeletePlaylist(c *gin.Context)
- func (h *Handler) DeletePlaylistGroup(c *gin.Context)
- func (h *Handler) GetChannel(c *gin.Context)
- func (h *Handler) GetChannelRegistry(c *gin.Context)
- func (h *Handler) GetPlaylist(c *gin.Context)
- func (h *Handler) GetPlaylistGroup(c *gin.Context)
- func (h *Handler) GetPlaylistItem(c *gin.Context)
- func (h *Handler) Health(c *gin.Context)
- func (h *Handler) HealthAPI(c *gin.Context)
- func (h *Handler) ListChannels(c *gin.Context)
- func (h *Handler) ListPlaylistGroups(c *gin.Context)
- func (h *Handler) ListPlaylistItems(c *gin.Context)
- func (h *Handler) ListPlaylists(c *gin.Context)
- func (h *Handler) ReplaceChannel(c *gin.Context)
- func (h *Handler) ReplaceChannelRegistry(c *gin.Context)
- func (h *Handler) ReplacePlaylist(c *gin.Context)
- func (h *Handler) ReplacePlaylistGroup(c *gin.Context)
- func (h *Handler) UpdateChannel(c *gin.Context)
- func (h *Handler) UpdatePlaylist(c *gin.Context)
- func (h *Handler) UpdatePlaylistGroup(c *gin.Context)
- type ListResponse
- type Server
Constants ¶
const ( DefaultListLimit = 100 MinListLimit = 1 MaxListLimit = 100 )
API list limits (public contract). Store enforces a higher ceiling separately.
Variables ¶
This section is empty.
Functions ¶
func APIKeyAuth ¶
func APIKeyAuth(secret string, log *zap.Logger) gin.HandlerFunc
APIKeyAuth requires Authorization: Bearer <secret> for mutating routes. Compares the full header value in constant time to reduce timing leakage of the API key length/prefix.
func NormalizeListLimit ¶
NormalizeListLimit clamps n to [MinListLimit, MaxListLimit]; zero or negative uses DefaultListLimit.
func ParseListLimitQuery ¶
ParseListLimitQuery parses the `limit` query parameter. Empty uses DefaultListLimit. Non-empty values must be decimal integers; the result is normalized to API bounds.
func RegisterRoutes ¶
RegisterRoutes attaches all HTTP routes to the Gin engine. POST and document PUT/PATCH use SignatureOrAPIKeyAuth (API key or signatures in body); DELETE and registry PUT use APIKeyAuth only.
func SetAuthMode ¶ added in v0.2.0
SetAuthMode stores the authentication mode in the Gin context for executor access.
func SignatureOrAPIKeyAuth ¶ added in v0.2.0
func SignatureOrAPIKeyAuth(secret string, log *zap.Logger) gin.HandlerFunc
SignatureOrAPIKeyAuth accepts either API key (ops path) or valid signatures in request body (user path). Used for POST (create) and PUT/PATCH (replace/update) on playlists, playlist-groups, and channels: requests with a non-empty signatures[] array may omit the API key; the executor verifies signatures.
Authentication flow:
- Path A (Ops): Has Authorization: Bearer header → validate API key → set AuthModeAPIKey
- Path B (User): No Authorization header but has signatures[] in body → set AuthModeSignature
- Reject: No Authorization header and no signatures in body
Types ¶
type AuthMode ¶ added in v0.2.0
type AuthMode int
AuthMode distinguishes API key (ops) vs signature-based (user) authentication paths.
func GetAuthMode ¶ added in v0.2.0
GetAuthMode retrieves the authentication mode from the Gin context; defaults to AuthModeAPIKey if not set.
type ErrorResponse ¶
ErrorResponse matches the feed OpenAPI error shape.
type Handler ¶
Handler carries the executor, logger, and build version for health/metadata responses.
func (*Handler) CreateChannel ¶
CreateChannel POST /api/v1/channels.
func (*Handler) CreatePlaylist ¶
CreatePlaylist POST /api/v1/playlists.
func (*Handler) CreatePlaylistGroup ¶
CreatePlaylistGroup POST /api/v1/playlist-groups.
func (*Handler) DeleteChannel ¶
DeleteChannel DELETE /api/v1/channels/:id.
func (*Handler) DeletePlaylist ¶
DeletePlaylist DELETE /api/v1/playlists/:id.
func (*Handler) DeletePlaylistGroup ¶
DeletePlaylistGroup DELETE /api/v1/playlist-groups/:id.
func (*Handler) GetChannel ¶
GetChannel GET /api/v1/channels/:id.
func (*Handler) GetChannelRegistry ¶
GetChannelRegistry GET /api/v1/registry/channels.
func (*Handler) GetPlaylist ¶
GetPlaylist GET /api/v1/playlists/:id.
func (*Handler) GetPlaylistGroup ¶
GetPlaylistGroup GET /api/v1/playlist-groups/:id.
func (*Handler) GetPlaylistItem ¶
GetPlaylistItem GET /api/v1/playlist-items/:id.
func (*Handler) Health ¶
Health is a liveness endpoint (no version prefix in plan; we expose both /health and /api/v1/health).
func (*Handler) ListChannels ¶
ListChannels GET /api/v1/channels.
func (*Handler) ListPlaylistGroups ¶
ListPlaylistGroups GET /api/v1/playlist-groups.
func (*Handler) ListPlaylistItems ¶
ListPlaylistItems GET /api/v1/playlist-items.
func (*Handler) ListPlaylists ¶
ListPlaylists GET /api/v1/playlists.
func (*Handler) ReplaceChannel ¶
ReplaceChannel PUT /api/v1/channels/:id.
func (*Handler) ReplaceChannelRegistry ¶
ReplaceChannelRegistry PUT /api/v1/registry/channels.
func (*Handler) ReplacePlaylist ¶
ReplacePlaylist PUT /api/v1/playlists/:id.
func (*Handler) ReplacePlaylistGroup ¶
ReplacePlaylistGroup PUT /api/v1/playlist-groups/:id.
func (*Handler) UpdateChannel ¶
UpdateChannel PATCH /api/v1/channels/:id.
func (*Handler) UpdatePlaylist ¶
UpdatePlaylist PATCH /api/v1/playlists/:id.
func (*Handler) UpdatePlaylistGroup ¶
UpdatePlaylistGroup PATCH /api/v1/playlist-groups/:id.
type ListResponse ¶
type ListResponse[T any] struct { Items []T `json:"items"` Cursor string `json:"cursor,omitempty"` HasMore bool `json:"hasMore"` }
ListResponse is the JSON envelope for GET list endpoints: items, optional cursor, hasMore.
func NewListResponse ¶
func NewListResponse[T any](items []T, nextCursor string) ListResponse[T]
NewListResponse sets HasMore from nextCursor (non-empty means another page exists).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps stdlib http.Server with the Gin engine built in New.
func New ¶
New builds a Gin engine: recovery, optional Sentry, Zap request logging, RegisterRoutes, and http.Server timeouts from cfg.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server (blocking).