- 20 Go source files, single 16MB binary - SQLite + FTS5 full-text search (pure Go, no CGO) - BCB integration: Selic, CDI, IPCA, USD/BRL, EUR/BRL - CVM integration: 2,524 companies from registry - Fiber v2 REST API with 42 handlers - Auto-seeds on first run (~5s for BCB + CVM) - Token bucket rate limiter, optional API key auth - Periodic sync scheduler (configurable) - Graceful shutdown, structured logging (slog) - All endpoints tested with real data
27 lines
502 B
Go
27 lines
502 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func NewAPIKeyAuth(apiKey string) fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
if c.Path() == "/health" {
|
|
return c.Next()
|
|
}
|
|
key := c.Get("X-API-Key")
|
|
if key == "" {
|
|
auth := c.Get("Authorization")
|
|
if strings.HasPrefix(auth, "Bearer ") {
|
|
key = strings.TrimPrefix(auth, "Bearer ")
|
|
}
|
|
}
|
|
if key != apiKey {
|
|
return c.Status(401).JSON(fiber.Map{"error": "unauthorized"})
|
|
}
|
|
return c.Next()
|
|
}
|
|
}
|