Skip to content

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),
),
)

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)
}

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()})
}
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"

Config path: modules.http.fiber.<name>

host string default: 0.0.0.0

host specifies the server's hostname or IP address to bind

env LAKTA_MODULES_HTTP_FIBER_<NAME>_HOST
port uint16 default: 8080

port specifies the port number the server listens on

env LAKTA_MODULES_HTTP_FIBER_<NAME>_PORT
health_path string

healthPath defines the endpoint path for the health check

env 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.

These options can only be set in Go code via With*() functions, not via config files or environment variables.

OptionTypeDescription
WithDefaults(...)*fiber.Configsets typed fiber.Config defaults that can be overridden by Raw/koanf values
WithRouter(...)[]fiber.Routeradds router to the list of routers to be invoked (code-only)