-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
74 lines (57 loc) · 1.51 KB
/
server.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
74
/*
@Author: Logan (Nam) Nguyen
@Course: SUNY Oswego - CSC 482
@Instructor: Professor James Early
*/
// @package: main
package main
// @import
import (
"NFTir/server/controllers"
"NFTir/server/dao"
"NFTir/server/db"
"NFTir/server/routers"
"NFTir/server/utils"
"os"
"github.com/gin-gonic/gin"
"github.com/jamespearly/loggly"
)
// @notice global variables
var (
server *gin.Engine
logglyClient *loggly.ClientType
nr *routers.NftRouter
)
// @dev Runs before main()
func init() {
// load env variables
if (os.Getenv("GIN_MODE") != "release") {utils.LoadEnvVars()}
// set up gin engine - Default With the Logger and Recovery middleware already attached
server = gin.Default()
// Gin trust all proxies by default and it's not safe. Set trusted proxy to home router to to mitigate
server.SetTrustedProxies([]string{os.Getenv("HOME_ROUTER")})
// init jearly/loggly
logglyClient = loggly.New("NFTir")
// init db connection
dbconn := db.EstablishAwsDynamodbSession()
// init nftirDao interface
nd := dao.NftirDaoConstructor(dbconn)
// init nftController
nc := controllers.NftirControllerConstructor(nd, logglyClient)
// init nftRouter
nr = routers.NftRouterConstructor(nc)
}
// @dev Root function
func main() {
server.HandleMethodNotAllowed = true
// base path
basePath := server.Group("nnguyen6")
// init handlers
nr.NftRoutes(*basePath)
// run server
if (os.Getenv("GIN_MODE") != "release") {
server.Run(os.Getenv("SOURCE_IP"))
} else {
server.Run(":"+os.Getenv("PRODUCTION_PORT"))
}
}