-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
70 lines (59 loc) · 1.51 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
66
67
68
69
70
package main
import (
"flag"
"fmt"
"os"
"strconv"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"GApp/AuthServer/auth"
"GApp/AuthServer/db"
"GApp/AuthServer/middlewares"
"GApp/AuthServer/test"
)
func main() {
operateMode := flag.String("mode", "deploy", "mode of operation. Options : ['deploy', 'test']")
flag.Parse()
if *operateMode == "deploy" {
fmt.Println("Deploy Mode")
err := godotenv.Load(".env")
if err != nil {
fmt.Println("Error loading .env file")
return
}
var SERVER_BIND_PORT int
var SERVER_BIND_ADDRESS string
SERVER_BIND_ADDRESS = os.Getenv("SERVER_BIND_URL")
if SERVER_BIND_ADDRESS == "" {
SERVER_BIND_ADDRESS = "localhost"
}
SERVER_BIND_PORT, err = strconv.Atoi(os.Getenv("SERVER_BIND_PORT"))
if err != nil {
fmt.Println("Error parsing SERVER_BIND_PORT to integer")
return
}
err = db.ConnectDb()
if err != nil {
fmt.Println("Can't connect to DB")
return
} else {
fmt.Println("Connected to DB")
}
router := gin.Default()
router.SetTrustedProxies(nil)
router.Use(middlewares.SetJsonTypeMiddleware())
router.POST("/register", auth.CreateUser)
fmt.Printf("Connecting to %s at PORT %d\n", SERVER_BIND_ADDRESS, SERVER_BIND_PORT)
router.Run(fmt.Sprintf("%s:%d", SERVER_BIND_ADDRESS, SERVER_BIND_PORT))
} else if *operateMode == "test" {
fmt.Println("Test Mode")
err := godotenv.Load(".env.test")
if err != nil {
fmt.Println("Error loading .env file")
return
}
test.TestMain()
} else {
fmt.Println("Invalid Mode")
}
}