-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (50 loc) · 1.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
package main
import (
"fmt"
"go-devops-admin/cmd"
"go-devops-admin/cmd/make"
"go-devops-admin/bootstrap"
btsConfig "go-devops-admin/config"
"go-devops-admin/pkg/config"
"go-devops-admin/pkg/console"
"os"
"github.com/spf13/cobra"
)
func init() {
btsConfig.Initialize()
}
func main() {
var rootCmd = &cobra.Command{
Use: "GoDev",
Short: "A simple from project",
Long: `Default will run "server" command, you can use "-h" flag to see all command`,
// rootCmd 所有子命令都会执行以下代码
PersistentPreRun: func(command *cobra.Command, args []string) {
// 配置初始化, 依赖命令行 --env 参数
config.InitConfig(cmd.Env)
// 初始化日志配置
bootstrap.SetupLogger()
// 初始化 DB
bootstrap.SetupDB()
// 初始化 Redis
bootstrap.SetupRedis()
// 初始化业务缓存
bootstrap.SetupCache()
},
}
// 注册子命令
rootCmd.AddCommand(
cmd.CmdServer,
cmd.CmdKey,
cmd.PlayCmd,
cmd.CmdMigrate,
cmd.CmdSeed,
make.CmdMake,
)
// 配置默认运行 Web 服务
cmd.RegisterDefaultCommand(rootCmd, cmd.CmdServer)
// 执行主命令
if err := rootCmd.Execute(); err != nil {
console.Exit(fmt.Sprintf("Failed to run app with %v: %s", os.Args, err.Error()))
}
}