Documentation
¶
Index ¶
- func APIKeyMiddleware(db *gorm.DB) func(http.Handler) http.Handler
- func AdminAuthMiddleware(secretKey string) func(http.Handler) http.Handler
- func CORSMiddleware(allowAll bool) func(http.Handler) http.Handler
- func GetAPIKeyFromContext(r *http.Request) *models.APIKey
- func MaxBodyBytesMiddleware(limit int64) func(http.Handler) http.Handler
- func NewRouter(db *gorm.DB, secretKey string, cfg RouterConfig) http.Handler
- func PerKeyRateLimitMiddleware() func(http.Handler) http.Handler
- func RateLimitMiddleware(requestsPerMinute int) func(http.Handler) http.Handler
- func SecurityHeadersMiddleware(enableHSTS bool) func(http.Handler) http.Handler
- type AdminHandler
- func (h *AdminHandler) ChangePassword(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) CreateKey(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) DeleteKey(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) GetKey(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) GetSettings(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) HISCalibration(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) KeyStats(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) KeysStatsSummary(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) ListKeys(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) Login(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) Me(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) RotateSecret(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) StatsOverview(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) UpdateKey(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) UpdateSettings(w http.ResponseWriter, r *http.Request)
- func (h *AdminHandler) Version(w http.ResponseWriter, r *http.Request)
- type ChallengeHandler
- type PublicHandler
- type RouterConfig
- type VerifyHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdminAuthMiddleware ¶
func MaxBodyBytesMiddleware ¶
MaxBodyBytesMiddleware caps the size of request bodies to guard against memory-exhaustion. An oversized body surfaces as a read error, which the JSON-decoding handlers already translate into a 4xx response.
func PerKeyRateLimitMiddleware ¶
PerKeyRateLimitMiddleware enforces each API key's own RateLimitPerMin budget, independent of the global per-IP limiter. It must run after APIKeyMiddleware so the authenticated key is available on the request context; keys with a limit of 0 are never throttled here.
func RateLimitMiddleware ¶
RateLimitMiddleware limits requests per client IP over a one-minute window and answers with a JSON 429 when the limit is exceeded.
func SecurityHeadersMiddleware ¶
SecurityHeadersMiddleware sets a baseline of security-related response headers. HSTS is opt-in because GateCHA is commonly run over plain HTTP locally or behind a TLS-terminating reverse proxy.
Types ¶
type AdminHandler ¶
func (*AdminHandler) ChangePassword ¶
func (h *AdminHandler) ChangePassword(w http.ResponseWriter, r *http.Request)
POST /api/admin/change-password
func (*AdminHandler) CreateKey ¶
func (h *AdminHandler) CreateKey(w http.ResponseWriter, r *http.Request)
POST /api/admin/keys
func (*AdminHandler) DeleteKey ¶
func (h *AdminHandler) DeleteKey(w http.ResponseWriter, r *http.Request)
DELETE /api/admin/keys/{id}
func (*AdminHandler) GetKey ¶
func (h *AdminHandler) GetKey(w http.ResponseWriter, r *http.Request)
GET /api/admin/keys/{id}
func (*AdminHandler) GetSettings ¶
func (h *AdminHandler) GetSettings(w http.ResponseWriter, r *http.Request)
GET /api/admin/settings
func (*AdminHandler) HISCalibration ¶
func (h *AdminHandler) HISCalibration(w http.ResponseWriter, r *http.Request)
GET /api/admin/his/calibration?key_id=&days= Returns the score distribution and signal averages over stored HIS samples, to help calibrate an enforcement threshold before any blocking is enabled.
func (*AdminHandler) KeyStats ¶
func (h *AdminHandler) KeyStats(w http.ResponseWriter, r *http.Request)
GET /api/admin/stats/keys/{id}
func (*AdminHandler) KeysStatsSummary ¶
func (h *AdminHandler) KeysStatsSummary(w http.ResponseWriter, r *http.Request)
GET /api/admin/stats/keys-summary
func (*AdminHandler) ListKeys ¶
func (h *AdminHandler) ListKeys(w http.ResponseWriter, r *http.Request)
GET /api/admin/keys
func (*AdminHandler) Login ¶
func (h *AdminHandler) Login(w http.ResponseWriter, r *http.Request)
POST /api/admin/login
func (*AdminHandler) Me ¶
func (h *AdminHandler) Me(w http.ResponseWriter, r *http.Request)
GET /api/admin/me
func (*AdminHandler) RotateSecret ¶
func (h *AdminHandler) RotateSecret(w http.ResponseWriter, r *http.Request)
POST /api/admin/keys/{id}/rotate-secret
func (*AdminHandler) StatsOverview ¶
func (h *AdminHandler) StatsOverview(w http.ResponseWriter, r *http.Request)
GET /api/admin/stats/overview
func (*AdminHandler) UpdateKey ¶
func (h *AdminHandler) UpdateKey(w http.ResponseWriter, r *http.Request)
PUT /api/admin/keys/{id}
func (*AdminHandler) UpdateSettings ¶
func (h *AdminHandler) UpdateSettings(w http.ResponseWriter, r *http.Request)
PUT /api/admin/settings
func (*AdminHandler) Version ¶
func (h *AdminHandler) Version(w http.ResponseWriter, r *http.Request)
GET /api/admin/version Returns the build version. Kept behind admin auth so the running version is not disclosed to unauthenticated visitors.
type ChallengeHandler ¶
type ChallengeHandler struct {
DB *gorm.DB
// Adaptive scales proof-of-work difficulty by source request rate for keys
// that opt in via AdaptiveDifficulty.
Adaptive *adaptiveLimiter
}
func (*ChallengeHandler) ServeHTTP ¶
func (h *ChallengeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type PublicHandler ¶
func (*PublicHandler) LoginConfig ¶
func (h *PublicHandler) LoginConfig(w http.ResponseWriter, r *http.Request)
GET /api/public/login-config
type RouterConfig ¶
type RouterConfig struct {
CORSAllowAll bool
TrustProxy bool // honor X-Forwarded-For/X-Real-IP (only safe behind a trusted proxy)
EnableHSTS bool
MaxBodyBytes int64
RateLimitEnabled bool
RateLimitLogin int // requests per minute on /api/admin/login
RateLimitAPI int // requests per minute on /api/v1/*
Version string // build version surfaced to authenticated admins
}
RouterConfig holds the request-handling and hardening options for NewRouter.
type VerifyHandler ¶
func (*VerifyHandler) ServeHTTP ¶
func (h *VerifyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)