-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) 路 1023 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
package main
import (
"log"
"github.com/chaiyapatoam/go-clean-fiber-boiler/db"
"github.com/chaiyapatoam/go-clean-fiber-boiler/internal/config"
"github.com/chaiyapatoam/go-clean-fiber-boiler/route"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/helmet"
)
func main() {
env := config.LoadEnv()
db, err := db.ConnectDB(env.MYSQL_URI)
if err != nil {
log.Fatal("Cant Connect To Mysql : ", err)
}
app := fiber.New()
app.Use(helmet.New())
app.Use(cors.New(cors.Config{
AllowHeaders: "Origin,Content-Type,Accept,Content-Length,Accept-Language,Accept-Encoding,Connection,Access-Control-Allow-Origin",
AllowOrigins: "http://localhost:3000, http://localhost:5173",
AllowCredentials: true,
AllowMethods: "GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS",
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.JSON(&fiber.Map{"message": "Hello World"})
})
route.MainRoute(app, db, env)
log.Fatal(app.Listen(":" + env.PORT))
}