-
Notifications
You must be signed in to change notification settings - Fork 1
/
gin_init.go
45 lines (41 loc) · 1.15 KB
/
gin_init.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
package test_utils
import (
"flag"
"os"
"strings"
"github.com/fwtpe/owl-backend/modules/f2e-api/app/controller"
"github.com/fwtpe/owl-backend/modules/f2e-api/config"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
var routes *gin.Engine
func SetUpGin() *gin.Engine {
if routes != nil {
return routes
} else {
confPath := flag.String("conf", "test_cfg", "set test configure file's name")
viper.AddConfigPath(".")
viper.AddConfigPath("/")
viper.AddConfigPath("../../../")
viper.AddConfigPath("../../../../")
viper.SetConfigName(*confPath)
err := viper.ReadInConfig()
if err != nil {
log.Error(err.Error())
}
rtCheck := viper.GetString("lambda_extends.root_dir")
if strings.Contains(rtCheck, "${GOPATH}") {
gofpath := os.Getenv("GOPATH") + "/src"
rtCheck = strings.Replace(rtCheck, "${GOPATH}", gofpath, -1)
viper.Set("lambda_extends.root_dir", rtCheck)
}
gin.SetMode(gin.TestMode)
log.SetLevel(log.DebugLevel)
config.InitDB(viper.GetBool("db.db_debug"))
//test with default set of db
routes := gin.Default()
routes = controller.StartGin(":9898", routes, true)
return routes
}
}