-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·65 lines (53 loc) · 1.48 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/NetSepio/erebrus-gateway/api"
"github.com/NetSepio/erebrus-gateway/api/v1/client"
"github.com/NetSepio/erebrus-gateway/app"
"github.com/NetSepio/erebrus-gateway/config/dbconfig"
"github.com/NetSepio/erebrus-gateway/config/redisconfig"
"github.com/NetSepio/erebrus-gateway/util/pkg/logwrapper"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func init() {
godotenv.Load()
redisconfig.RedisConnection()
}
func main() {
logwrapper.Init()
app.Init()
ginApp := gin.Default()
if err := dbconfig.DbMigrations(); err != nil {
logwrapper.Errorf("Error mirating to database: %v", err)
}
if os.Getenv("DB_HOST") == "debug" {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
// cors middleware
config := cors.DefaultConfig()
config.AllowAllOrigins = true
config.AllowHeaders = []string{"Authorization", "Content-Type"}
ginApp.Use(cors.New(config))
// adding health check
ginApp.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "pong"})
})
ginApp.NoRoute(func(c *gin.Context) {
c.JSON(404, gin.H{"status": 404, "message": "Invalid Endpoint Request"})
})
go client.AutoClientDelete()
api.ApplyRoutes(ginApp)
ginApp.Run(":" + os.Getenv("HTTP_PORT"))
// wait for a SIGINT or SIGTERM signal
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
fmt.Println("Received signal, shutting down...")
}