HTTP (Fiber)
pkg/http/fiber runs a Fiber v3 HTTP server as a SyncModule.
Pass routes via WithRouter and Fiber defaults via WithDefaults. No separate module needed.
lakta.NewRuntime( config.NewModule( config.WithConfigDirs(".", "./config"), config.WithArgs(os.Args[1:]), ), tint.NewModule(), slog.NewModule(), otel.NewModule(), health.NewModule(), grpcclient.NewModule( grpcclient.WithName("data"), grpcclient.WithClient(v1.NewDataServiceClient), ), fiberserver.NewModule( fiberserver.WithDefaults(fiber.Config{ ReadTimeout: 30 * time.Second, WriteTimeout: 30 * time.Second, }), fiberserver.WithRouter(registerRoutes), ),)Registering routes
Section titled “Registering routes”WithRouter receives the fully initialized *fiber.App. Register all routes in one place:
func registerRoutes(app *fiber.App) { app.Get("/items", listItems) app.Get("/items/:id", getItem) app.Post("/items", createItem)}Accessing DI in handlers
Section titled “Accessing DI in handlers”Use lakta.Invoke[T](c.Context()) — the request context carries the injector:
func listItems(c fiber.Ctx) error { client, err := lakta.Invoke[v1.DataServiceClient](c.Context()) if err != nil { return err }
resp, err := client.ListItems(c.Context(), &v1.ListItemsRequest{ Limit: uint64(fiber.Query[int](c, "limit", 20)), Offset: uint64(fiber.Query[int](c, "offset", 0)), }) if err != nil { return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()}) }
return c.JSON(fiber.Map{"items": resp.GetItems()})}Multi-instance
Section titled “Multi-instance”fiberserver.NewModule(fiberserver.WithName("admin"), fiberserver.WithRouter(adminRoutes)),fiberserver.NewModule(fiberserver.WithName("public"), fiberserver.WithRouter(publicRoutes)),modules: http: fiber: admin: port: 9090 health_path: "/health" public: port: 8080 health_path: "/health"Configuration Reference
Section titled “Configuration Reference”Config path: modules.http.fiber.<name>
host host specifies the server's hostname or IP address to bind
LAKTA_MODULES_HTTP_FIBER_<NAME>_HOST port port specifies the port number the server listens on
LAKTA_MODULES_HTTP_FIBER_<NAME>_PORT health_path healthPath defines the endpoint path for the health check
LAKTA_MODULES_HTTP_FIBER_<NAME>_HEALTH_PATH
Additional fields are passed through to github.com/gofiber/fiber/v3 Config
via mapstructure. See Config Passthrough for details.
Code-only options
Section titled “Code-only options”These options can only be set in Go code via With*() functions, not via config files or environment variables.
| Option | Type | Description |
|---|---|---|
WithDefaults(...) | *fiber.Config | sets typed fiber.Config defaults that can be overridden by Raw/koanf values |
WithRouter(...) | []fiber.Router | adds router to the list of routers to be invoked (code-only) |