-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (99 loc) · 2.28 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
package main
import (
"context"
"os"
app "github.com/flytrap/telegram-bot/internal"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
var VERSION = "0.6.26"
func main() {
ctx := context.Background()
app := cli.NewApp()
app.Name = "telegram-bot"
app.Version = VERSION
app.Usage = "telegram-bot based on GRPC + WIRE."
app.Commands = []*cli.Command{
newIndexCmd(ctx), newGrpcCmd(ctx), newManagerCmd(ctx),
}
err := app.Run(os.Args)
if err != nil {
logrus.Error(err.Error())
}
}
func newIndexCmd(ctx context.Context) *cli.Command {
return &cli.Command{
Name: "index",
Usage: "Run tg-bot index server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "conf",
Aliases: []string{"c"},
Required: true,
Usage: "指定启动配置文件(.json,.yaml,.toml)",
},
&cli.IntFlag{
Name: "update",
Aliases: []string{"u"},
Usage: "更新索引原始数据",
Required: false,
DefaultText: "0",
},
&cli.StringFlag{
Name: "index",
Aliases: []string{"i"},
Usage: "索引操作(load|delete)",
Required: false,
DefaultText: "",
},
},
Action: func(c *cli.Context) error {
return app.RunIndex(ctx,
app.SetConfigFile(c.String("conf")),
app.SetVersion(VERSION),
app.SetUpdateDb(c.Int64("update")),
app.SetIndex(c.String("index")),
)
},
}
}
func newManagerCmd(ctx context.Context) *cli.Command {
return &cli.Command{
Name: "manager",
Usage: "Run tg-bot manager server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "conf",
Aliases: []string{"c"},
Required: true,
Usage: "指定启动配置文件(.json,.yaml,.toml)",
},
},
Action: func(c *cli.Context) error {
return app.RunManager(ctx,
app.SetConfigFile(c.String("conf")),
app.SetVersion(VERSION),
)
},
}
}
func newGrpcCmd(ctx context.Context) *cli.Command {
return &cli.Command{
Name: "grpc",
Usage: "Run tg-bot grpc server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "conf",
Aliases: []string{"c"},
Required: true,
Usage: "指定启动配置文件(.json,.yaml,.toml)",
},
},
Action: func(c *cli.Context) error {
return app.RunGrpc(ctx,
app.SetConfigFile(c.String("conf")),
app.SetVersion(VERSION),
)
},
}
}