-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.go
73 lines (53 loc) · 1.02 KB
/
app.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
package artifact
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
var Res ResponseBuilder
func LoadRoute() {
gin.ForceConsoleColor()
//gin.SetMode("debug")
Router = gin.Default()
//httpRouter.SetTrustedProxies([]string{"0.0.0.0"})
Router.GET("/health-check", func(c *gin.Context) {
Res.Code(http.StatusOK).Message("Up and Running").Data(gin.H{"app": "OK"}).Json(c)
})
}
func LoadConfig() {
Config = NewConfig()
Config.Load()
}
func InitializeLogger() LoggerBuilder {
return NewLogger()
}
func DatabaseConnection() error {
db, err := NewDatabase()
if err != nil {
return err
}
DB = db
return nil
}
func NoSqlConnection() {
Mongo = NewNoSqlDB()
}
func New() {
LoadConfig()
LoadRoute()
}
func Start() {
NoSqlConnection()
InitializeLogger()
}
func Run() {
if Mongo != nil {
defer Mongo.Client.Disconnect(Mongo.Ctx)
}
port, _ := Config.Int("App.Port")
if port == 0 {
port = 8080
}
fmt.Println("Server is running on port", fmt.Sprintf(":%d", port))
Router.Run(fmt.Sprintf(":%d", port))
}