-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
123 lines (108 loc) · 2.87 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"github.com/urfave/cli"
"os"
"fmt"
"runtime"
"monomer-service-demo/cmd"
"github.com/sunmi-OS/gocore/sqlite"
)
const banner = `
_ _ _
(_) | | (_)
____ ___ ____ ___ ____ _____ ____ ___ _____ ____ _ _ _ ____ _____ __| |_____ ____ ___ _____ _____ ___ _ _ ____ ____ _
| \ / _ \| _ \ / _ \| \| ___ |/ ___) /___) ___ |/ ___) | | | |/ ___) ___ | / _ | ___ | \ / _ \ (_____|_____) /___) | | | _ \| \| |
| | | | |_| | | | | |_| | | | | ____| | |___ | ____| | \ V /| ( (___| ____| ( (_| | ____| | | | |_| | |___ | |_| | | | | | | | |
|_|_|_|\___/|_| |_|\___/|_|_|_|_____)_| (___/|_____)_| \_/ |_|\____)_____) \____|_____)_|_|_|\___/ (___/|____/|_| |_|_|_|_|_|
`
const (
version = "1.0.0"
name = "monomer-service-demo"
)
func main() {
// 打印log
fmt.Print(banner)
// 配置核心
runtime.GOMAXPROCS(runtime.NumCPU())
// 初始化数据库
sqlite.NewDB("dbDefault")
app := cli.NewApp()
app.Name = name
app.Email = "[email protected]"
app.Version = version
app.Action = runAll
app.Commands = []cli.Command{
{
Name: "web",
Aliases: []string{"w"},
Usage: "web静态业务服务",
Subcommands: []cli.Command{
{
Name: "start",
Usage: "开始运行WEB容器提供web访问",
Action: cmd.RunWeb,
},
},
}, {
Name: "api",
Aliases: []string{"w"},
Usage: "api接口服务",
Subcommands: []cli.Command{
{
Name: "start",
Usage: "开发运行接口服务",
Action: cmd.RunApi,
},
},
}, {
Name: "db",
Aliases: []string{"w"},
Usage: "数据服务",
Subcommands: []cli.Command{
{
Name: "CreateTable",
Usage: "run emq test qos0",
Action: cmd.CreateTable,
},
{
Name: "UpdateTableV1_1",
Usage: "run emq test qos0",
Action: cmd.UpdateTableV1_1,
},
},
}, {
Name: "all",
Aliases: []string{"w"},
Usage: "全部服务",
Subcommands: []cli.Command{
{
Name: "start",
Usage: "所有服务同时运行",
Action: runAll,
},
},
}, {
Name: "benchmark",
Aliases: []string{"w"},
Usage: "基准测试",
Subcommands: []cli.Command{
{
Name: "run_db_write",
Usage: "进行数据写入测试",
Action: cmd.RunDBWrite,
},
{
Name: "run_db_read",
Usage: "进行数据读取入测试",
Action: cmd.RunDBRead,
},
},
},
}
app.Run(os.Args)
}
func runAll(c *cli.Context) error {
cmd.CreateTable(c)
go cmd.RunWeb(c)
return cmd.RunApi(c)
}