-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (31 loc) · 879 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"log/slog"
"os"
"time"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/logger"
"github.com/gofiber/fiber/v3/middleware/recover"
_ "github.com/joho/godotenv/autoload"
"github.com/dominikwinter/slackgpt/internal/router"
)
func main() {
var level slog.Leveler
if os.Getenv("DEBUG") == "true" {
level = slog.LevelDebug
} else {
level = slog.LevelInfo
}
log := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
app := fiber.New(fiber.Config{
ReadTimeout: 30 * time.Second,
IdleTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
})
app.Use(recover.New(recover.Config{EnableStackTrace: true}))
app.Use(logger.New())
router.Setup(app, log)
if err := app.Listen(":" + os.Getenv("PORT")); err != nil {
log.Error("failed to start server", slog.Any("error", err))
}
}