-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.go
105 lines (90 loc) · 2.23 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"net/http"
"os"
"github.com/colinrs/ffly-plus/models"
"github.com/colinrs/ffly-plus/internal/config"
"github.com/colinrs/ffly-plus/internal/sentinelm"
"github.com/colinrs/ffly-plus/internal/version"
"github.com/colinrs/ffly-plus/router"
"github.com/colinrs/ffly-plus/rpc"
serverGin "github.com/colinrs/pkgx/server/gin"
"github.com/arl/statsviz"
"github.com/urfave/cli"
)
// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host petstore.swagger.io:8080
// @BasePath /api/v1
func main() {
app := cli.NewApp()
app.Name = "ffly-plus"
app.Usage = "ffly-plus -c config/config.local.json"
printVersion := false
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "conf, c",
Value: "config/config.local.json",
Usage: "config/config.{local|dev|test|pre|prod}.json",
},
cli.BoolFlag{
Name: "version, v",
Required: false,
Usage: "-v",
Destination: &printVersion,
},
}
app.Action = func(c *cli.Context) error {
if printVersion {
fmt.Printf("{%#v}", version.Get())
return nil
}
conf := c.String("conf")
config.Init(conf)
err := sentinelm.InitSentinelByCustom()
if err != nil {
return err
}
err = models.Database(config.Conf.MySQL)
if err != nil {
return err
}
if err = InitValidator(); err != nil {
return err
}
go func() {
err = rpc.InitRPCService()
if err != nil {
panic(err)
}
}()
server := router.InitRouter()
go runMonti()
server.GinEngine.Run(":8000")
return nil
}
app.Run(os.Args)
}
func runMonti() {
// Register statsviz handlers on the default serve mux.
statsviz.RegisterDefault()
http.ListenAndServe(":8001", nil)
}
// InitValidator ...
func InitValidator() error {
var validateFuns []*serverGin.ValidateFuncs
validateFuns = append(validateFuns, &serverGin.ValidateFuncs{
TagName: "ccless",
Fn: serverGin.IsLess,
Message: "{0} not less:{1}",
})
return serverGin.InitValidator(validateFuns)
}