-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (55 loc) · 1.13 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
package main
import (
"Xmq/config"
"Xmq/logger"
"Xmq/persist"
rc "Xmq/registrationCenter"
"Xmq/server"
"os"
"time"
"github.com/urfave/cli/v2"
)
var (
cmdStart = cli.Command{
Name: "start",
Usage: "start server. For example: ./Xmq start -c config/config.yaml",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "c",
Usage: "Load configuration from `FILE`",
},
},
Action: func(c *cli.Context) error {
config.GetConfig(c.String("c"))
persist.PersistInit()
rc.RcInit()
server := server.NewServerFromConfig()
if err := server.Online(); err != nil {
logger.Errorf("Online failed: %v", err)
}
server.RunWithGrpc()
return nil
},
}
)
func main() {
app := newapp(&cmdStart)
_ = app.Run(os.Args)
}
func newapp(startCmd *cli.Command) *cli.App {
app := cli.NewApp()
app.Name = "Xmq"
app.Compiled = time.Now()
app.Usage = "A High Performance Xmq Server written in Go."
app.Flags = cmdStart.Flags
app.Commands = []*cli.Command{
&cmdStart,
}
app.Action = func(c *cli.Context) error {
if c.NumFlags() == 0 {
return cli.ShowAppHelp(c)
}
return startCmd.Action(c)
}
return app
}