-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
61 lines (48 loc) · 1.08 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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/gin-gonic/gin"
"github.com/spf13/pflag"
"github.com/spf13/viper"
routers "github.com/1024casts/fastim/router"
"github.com/1024casts/snake/pkg/snake"
v "github.com/1024casts/snake/pkg/version"
"github.com/1024casts/snake/pkg/conf"
)
var (
cfg = pflag.StringP("config", "c", "", "fastim config file path.")
version = pflag.BoolP("version", "v", false, "show version info.")
)
func main() {
pflag.Parse()
if *version {
ver := v.Get()
marshaled, err := json.MarshalIndent(&ver, "", " ")
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
fmt.Println(string(marshaled))
return
}
// init config
if err := conf.Init(*cfg); err != nil {
panic(err)
}
// init app
snake.App = snake.New(conf.Conf)
// Set gin mode.
gin.SetMode(snake.ModeRelease)
if viper.GetString("app.run_mode") == snake.ModeDebug {
gin.SetMode(snake.ModeDebug)
snake.App.DB.Debug()
}
// Create the Gin engine.
router := snake.App.Router
// API Routes.
routers.Load(router)
// start server
snake.App.Run()
}