// Package serviceboot provides shared service bootstrap helpers. package serviceboot import ( "fmt" "github.com/gofiber/fiber/v3" "knowfoolery/backend/shared/infra/utils/envutil" ) // Config defines basic service runtime settings. type Config struct { AppName string ServiceSlug string PortEnv string DefaultPort int } // NewFiberApp creates a Fiber app with shared defaults. func NewFiberApp(cfg Config) *fiber.App { return fiber.New(fiber.Config{ AppName: cfg.AppName, }) } // RegisterHealth registers a standard health endpoint. func RegisterHealth(app *fiber.App, serviceSlug string) { app.Get("/health", func(c fiber.Ctx) error { return c.JSON(fiber.Map{ "status": "healthy", "service": serviceSlug, }) }) } // ListenAddress resolves the listen port from environment with fallback. func ListenAddress(portEnv string, defaultPort int) string { port := envutil.Int(portEnv, defaultPort) if port < 1 || port > 65535 { port = defaultPort } if port < 1 || port > 65535 { port = 8080 } return fmt.Sprintf(":%d", port) } // Run starts the Fiber app. func Run(app *fiber.App, addr string) error { return app.Listen(addr) }