forked from LegalForceLawRAPC/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (58 loc) · 1.54 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/spf13/viper"
"github.com/LegalForceLawRAPC/go-template/api/cache"
"github.com/LegalForceLawRAPC/go-template/api/db"
"github.com/LegalForceLawRAPC/go-template/api/migrations"
"github.com/LegalForceLawRAPC/go-template/api/router"
gofibersentry "github.com/LegalForceLawRAPC/go-template/api/sentry"
"github.com/LegalForceLawRAPC/go-template/api/utils"
)
func healthCheck(c *fiber.Ctx) error {
return c.SendString("OK")
}
func main() {
// Set global configuration
utils.ImportEnv()
// Init redis
cache.GetRedis()
// Init Validators
utils.InitValidators()
// Create Fiber
app := fiber.New(fiber.Config{})
app.Get("/", healthCheck)
app.Get("/health", healthCheck)
// initialize sentry
gofibersentry.SentryInit()
sentryHandler := gofibersentry.New(gofibersentry.Options{})
app.Use(sentryHandler.Handle)
app.Use(logger.New(logger.Config{Next: func(c *fiber.Ctx) bool {
return strings.HasPrefix(c.Path(), "api")
}}))
app.Use(recover.New())
app.Use(cors.New(cors.Config{
AllowOrigins: "",
AllowHeaders: "*",
}))
//Connect and migrate the db
if viper.GetBool("MIGRATE") {
migrations.Migrate()
}
// Initialize DB
db.InitServices()
// Mount Routes
router.MountRoutes(app)
// Get Port
port := utils.GetPort()
// Start Fiber
err := app.Listen(fmt.Sprintf(":%s", port))
if err != nil {
panic(err)
}
}