Documentation
¶
Index ¶
- Constants
- func AdminAuth(apiKey string) fiber.Handler
- func CORS() fiber.Handler
- func ErrorHandler(c fiber.Ctx, err error) error
- func GetDBFromContext(c fiber.Ctx) (*sql.DB, error)
- func GetServiceFromContext(c fiber.Ctx) (*service.Service, error)
- func RateLimit(limiter *RateLimiter) fiber.Handler
- func RequestLogger() fiber.Handler
- func ServiceContext(mgr service.ServiceManager) fiber.Handler
- func SetDBInContext(c fiber.Ctx, db *sql.DB)
- type AppError
- func NewInternalError(msg string) *AppError
- func NewInvalidRequestError(msg string) *AppError
- func NewMissingHeaderError(header string) *AppError
- func NewOpenRouterError(msg string, status int) *AppError
- func NewServiceNotFoundError(id string) *AppError
- func NewUnauthorizedError(msg string) *AppError
- type RateLimiter
Constants ¶
const ( CodeServiceNotFound = "SERVICE_NOT_FOUND" CodeInvalidRequest = "INVALID_REQUEST" CodeOpenRouterError = "OPENROUTER_ERROR" CodeRateLimited = "RATE_LIMITED" CodeInternalError = "INTERNAL_ERROR" CodeMissingHeader = "MISSING_HEADER" )
Error code constants
Variables ¶
This section is empty.
Functions ¶
func AdminAuth ¶
AdminAuth returns middleware that validates a Bearer token against the configured API key. If apiKey is empty, auth is disabled (passthrough).
func ErrorHandler ¶
ErrorHandler is the custom Fiber error handler.
func GetDBFromContext ¶
GetDBFromContext retrieves the DB connection stored by ServiceContext middleware.
func GetServiceFromContext ¶
GetServiceFromContext retrieves the service stored by ServiceContext middleware.
func RateLimit ¶
func RateLimit(limiter *RateLimiter) fiber.Handler
RateLimit returns middleware that applies the given RateLimiter.
func RequestLogger ¶
RequestLogger returns middleware that logs every request with structured fields.
func ServiceContext ¶
func ServiceContext(mgr service.ServiceManager) fiber.Handler
ServiceContext returns middleware that extracts X-Service-ID and loads the service and its DB connection into the request context.
Types ¶
type AppError ¶
AppError is a structured application error.
func NewInternalError ¶
func NewInvalidRequestError ¶
func NewMissingHeaderError ¶
func NewOpenRouterError ¶
func NewServiceNotFoundError ¶
func NewUnauthorizedError ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements an in-memory per-IP token bucket rate limiter.
func NewRateLimiter ¶
func NewRateLimiter(requestsPerSecond int) *RateLimiter
NewRateLimiter creates a rate limiter allowing requestsPerSecond per IP.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(ip string) bool
Allow checks whether the given IP is allowed to make a request.
func (*RateLimiter) Close ¶
func (rl *RateLimiter) Close()
Close stops the background cleanup goroutine.