api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package api provides the HTTP server, middleware, and request handlers.

Index

Constants

View Source
const (
	// General per-IP rate limit
	RPS   = 30
	Burst = 50

	// Body size limit
	MaxBodySize = 1 << 20
)

Variables

This section is empty.

Functions

func AgentWS added in v0.1.2

func AgentWS(state *state.State) http.HandlerFunc

AgentWS accepts WebSocket connections from agents pushing config updates.

func EventStream

func EventStream(ctx context.Context, state *state.State) http.HandlerFunc

EventStream returns an SSE endpoint that pushes config updates to clients.

func Login

func Login(token string) http.HandlerFunc

Login validates the secret and sets an access cookie.

func Logout

func Logout() http.HandlerFunc

Logout clears the access cookie.

func PublishConfig

func PublishConfig(state *state.State) http.HandlerFunc

PublishConfig returns the merged traefik config as JSON or YAML.

func PublishEnvs

func PublishEnvs(state *state.State) http.HandlerFunc

PublishEnvs returns a list of registered environment names.

func WithBodyLimit

func WithBodyLimit(next http.Handler) http.Handler

WithBodyLimit rejects requests larger than MaxBodySize.

func WithRateLimit

func WithRateLimit(next http.Handler) http.Handler

WithRateLimit enforces per-IP request limits, cleaning stale entries every minute.

func WithSecurityHeaders

func WithSecurityHeaders(next http.Handler) http.Handler

WithSecurityHeaders sets common security response headers.

Types

type Chain

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

Chain composes middleware constructors into a pipeline.

func NewChain

func NewChain(constructors ...Constructor) Chain

NewChain returns a Chain that applies each constructor in order.

func (Chain) Then

func (c Chain) Then(h http.Handler) http.Handler

Then wraps the handler with all middleware in the chain.

func (Chain) ThenFunc

func (c Chain) ThenFunc(fn http.HandlerFunc) http.Handler

ThenFunc is like Then but accepts a handler function.

type Constructor

type Constructor func(http.Handler) http.Handler

Constructor wraps middleware that transforms an http.Handler.

type LoginRequest

type LoginRequest struct {
	Secret string `json:"secret"`
}

type Server

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

func New

func New(cfg *config.Config) *Server

func (*Server) Start

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

func (*Server) WithAuth added in v0.1.2

func (s *Server) WithAuth(next http.Handler) http.Handler

WithAuth checks the request token before calling the next handler.

func (*Server) WithLogger added in v0.1.2

func (s *Server) WithLogger(next http.Handler) http.Handler

WithLogger logs request method, path, status, duration, and client IP.

type UpdateRequest added in v0.1.2

type UpdateRequest struct {
	Env    string          `json:"env"`
	Name   string          `json:"name"`
	Config json.RawMessage `json:"config"`
}

Jump to

Keyboard shortcuts

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