You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB
Go

package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func main() {
app := fiber.New(fiber.Config{
AppName: "Know Foolery Session Service v1.0.0",
ServerHeader: "Session Service",
})
// Middleware
app.Use(logger.New(logger.Config{
Format: "[${time}] ${status} - ${method} ${path} ${latency}\n",
}))
app.Use(cors.New())
// Health endpoint
app.Get("/health", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"status": "healthy",
"service": "session-service",
"version": "1.0.0",
})
})
// API routes
api := app.Group("/api/v1")
api.Get("/sessions", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"message": "Session service endpoint",
"sessions": []string{},
})
})
// Graceful shutdown
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
log.Println("Gracefully shutting down Session Service...")
_ = app.Shutdown()
}()
port := os.Getenv("PORT")
if port == "" {
port = "3005"
}
log.Printf("Session Service starting on port %s", port)
if err := app.Listen(":" + port); err != nil {
log.Printf("Error starting server: %v", err)
}
}