-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (40 loc) · 1.09 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/NetSepio/erebrus-gateway/api"
"github.com/NetSepio/erebrus-gateway/app"
"github.com/NetSepio/erebrus-gateway/config/dbconfig"
"github.com/NetSepio/erebrus-gateway/util/pkg/logwrapper"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
godotenv.Load()
logwrapper.Init()
app.Init()
ginApp := gin.Default()
dbconfig.DbInit()
// 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"})
})
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...")
}