App
The App struct is the central piece of ss-keel-core. It wraps a Fiber app and adds structured routing, logging, OpenAPI generation, graceful shutdown, and optional integrations.
Constructor
Section titled “Constructor”func core.New(cfg KConfig) *AppCreates a new App instance. Sets up Fiber with:
- Request logging middleware
- CORS middleware
- Panic recovery middleware
- Error handler (
*KError→ JSON response) GET /healthendpoint (unlessDisableHealth: true)GET /docsandGET /docs/openapi.json(unlessEnv: "production")
KConfig
Section titled “KConfig”type KConfig struct { ServiceName string Port int // default: 3000 Env string // "development" | "staging" | "production" DisableHealth bool Docs DocsConfig}DocsConfig
Section titled “DocsConfig”type DocsConfig struct { Path string // default: "/docs" Title string Version string // default: "1.0.0" Description string Contact *DocsContact License *DocsLicense Servers []string // format: "url - description" Tags []DocsTag}
type DocsContact struct { Name string URL string Email string}
type DocsLicense struct { Name string URL string}
type DocsTag struct { Name string Description string}Methods
Section titled “Methods”Registering Routes & Modules
Section titled “Registering Routes & Modules”func (a *App) RegisterController(c Controller)func (a *App) Use(m Module)func (a *App) Group(prefix string, middlewares ...fiber.Handler) *GroupStarting the Server
Section titled “Starting the Server”func (a *App) Listen() errorStarts the HTTP server in a goroutine, then blocks waiting for SIGINT or SIGTERM. On signal:
- Stops accepting new connections
- Runs all registered shutdown hooks with a 10-second timeout
- Exits
Shutdown Hooks
Section titled “Shutdown Hooks”func (a *App) OnShutdown(fn func(context.Context) error)Registers a function to be called during graceful shutdown. Hooks are run in registration order with a shared 10-second context.
app.OnShutdown(func(ctx context.Context) error { return db.Close()})Accessing Internals
Section titled “Accessing Internals”func (a *App) Logger() *logger.Loggerfunc (a *App) Fiber() *fiber.App // access underlying Fiber instancefunc (a *App) Tracer() Tracer // returns configured tracer (never nil)Observability
Section titled “Observability”func (a *App) SetMetricsCollector(mc MetricsCollector)func (a *App) SetTracer(t Tracer)func (a *App) SetTranslator(t Translator)Scheduler
Section titled “Scheduler”func (a *App) RegisterScheduler(s Scheduler)Registers a scheduler and automatically wires up a shutdown hook that calls s.Stop(ctx).
Health Checks
Section titled “Health Checks”func (a *App) RegisterHealthChecker(h HealthChecker)Adds a health checker. All checkers are run in parallel when GET /health is called. If any fails, the endpoint returns 503. See Health Checks.
Full Example
Section titled “Full Example”package main
import ( "context" "log" "github.com/slice-soft/ss-keel-core/core")
func main() { app := core.New(core.KConfig{ ServiceName: "users-api", Port: 8080, Env: "development", Docs: core.DocsConfig{ Title: "Users API", Version: "1.0.0", Description: "Manages user accounts", Contact: &core.DocsContact{ Name: "Support", Email: "dev@example.com", }, Servers: []string{ "http://localhost:8080 - Local", "https://api.example.com - Production", }, Tags: []core.DocsTag{ {Name: "users", Description: "User management"}, }, }, })
app.Use(&users.Module{})
app.OnShutdown(func(ctx context.Context) error { log.Println("shutting down...") return nil })
if err := app.Listen(); err != nil { log.Fatal(err) }}