-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (42 loc) · 967 Bytes
/
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
package main
import (
"errors"
"fmt"
"gin-web-skeleton/app/config"
"gin-web-skeleton/middleware"
"gin-web-skeleton/model"
"gin-web-skeleton/router"
"github.com/gin-gonic/gin"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"net/http"
"time"
)
var cfg = pflag.StringP("config", "c", "", "path")
func main() {
g := gin.New()
if err := config.Init(*cfg); err != nil {
panic(err)
}
router.InitRouter(g, middleware.Cors())
go func() {
if err := pingServer(); err != nil {
fmt.Println("The router bas been deployed successfully")
}
}()
model.DB.Init()
defer model.DB.Close()
fmt.Println(viper.GetString("jwt_secret"))
fmt.Println(viper.Get("db"))
g.Run(":8090")
}
func pingServer() error {
for i := 0; i < 2; i++ {
resp, err := http.Get("http://127.0.0.1:8090" + "/check/health")
if err == nil && resp.StatusCode == 200 {
return nil
}
time.Sleep(time.Second)
}
return errors.New("Cannot connect to the router.")
}