-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (37 loc) · 936 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
42
43
44
45
46
package main
import (
"absence-click/packages/databases"
"absence-click/routes"
"log"
"os"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
// load .env file
errEnv := godotenv.Load()
if errEnv != nil {
log.Fatalf("Error loading .env file: %v", errEnv.Error())
}
// declare port from .env
PORT := os.Getenv("PORT")
// initialize gin
gin.SetMode(gin.DebugMode)
r := gin.Default()
// initialize databases
databases.DBConn()
databases.DBMigration()
// initialize cors
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
AllowHeaders: []string{"X-Requested-With", "Content-Type", "Authorization"},
}))
// initialize routes
routes.RouteInit(r)
servErr := r.Run("localhost:" + PORT)
if servErr != nil {
log.Fatalf("Error starting server: %v", servErr.Error())
}
}