-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
94 lines (88 loc) · 3.82 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
package main
import (
"fmt"
"github.com/MQEnergy/gin-framework/bootstrap"
"github.com/MQEnergy/gin-framework/cmd"
"github.com/MQEnergy/gin-framework/config"
"github.com/MQEnergy/gin-framework/pkg/validator"
"github.com/MQEnergy/gin-framework/router"
"github.com/gogf/gf/v2/os/gtime"
"github.com/urfave/cli/v2"
"os"
"runtime"
)
var (
// AppName 当前应用名称
AppName = "gin-framework"
AppUsage = "使用gin框架作为基础开发库,封装一套适用于面向api编程的快速开发框架"
// Authors 作者
Authors = []*cli.Author{
{
Name: "chenxi",
Email: "[email protected]",
},
}
// AppPort 程序启动端口
AppPort string
// BuildVersion 编译的app版本
BuildVersion string
// BuildAt 编译时间
BuildAt string
// https://patorjk.com/software/taag/#p=testall&v=1&f=ANSI%20Shadow&t=O2O-AMQP%20
_UI = `
██████╗ ██╗███╗ ██╗ ███████╗██████╗ █████╗ ███╗ ███╗███████╗██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗
██╔════╝ ██║████╗ ██║ ██╔════╝██╔══██╗██╔══██╗████╗ ████║██╔════╝██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝
██║ ███╗██║██╔██╗ ██║█████╗█████╗ ██████╔╝███████║██╔████╔██║█████╗ ██║ █╗ ██║██║ ██║██████╔╝█████╔╝
██║ ██║██║██║╚██╗██║╚════╝██╔══╝ ██╔══██╗██╔══██║██║╚██╔╝██║██╔══╝ ██║███╗██║██║ ██║██╔══██╗██╔═██╗
╚██████╔╝██║██║ ╚████║ ██║ ██║ ██║██║ ██║██║ ╚═╝ ██║███████╗╚███╔███╔╝╚██████╔╝██║ ██║██║ ██╗
╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
`
)
// Stack 程序运行前的处理
func Stack() *cli.App {
buildInfo := fmt.Sprintf("%s-%s-%s-%s-%s", runtime.GOOS, runtime.GOARCH, BuildVersion, BuildAt, gtime.Now())
return &cli.App{
Name: AppName,
Version: buildInfo,
Usage: AppUsage,
Authors: Authors,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "env",
Aliases: []string{"e"},
Value: "dev",
Usage: "请选择配置文件 [dev | test | prod]",
Destination: &config.ConfEnv,
},
&cli.StringFlag{
Name: "port",
Aliases: []string{"p"},
Value: "9527",
Usage: "请选择启动端口",
Destination: &AppPort,
},
},
Action: func(context *cli.Context) error {
fmt.Println(fmt.Sprintf("\u001B[34m%s\u001B[0m", _UI))
// 程序启动时需要加载的服务
bootstrap.BootService()
// 引入验证翻译器
validator.NewValidate()
// 注册路由 启动程序
return router.Register().Run(":" + AppPort)
},
Commands: []*cli.Command{
cmd.MigrationCmd(), // 数据库迁移
cmd.AccountCmd(), // 管理账号创建
cmd.ModelCmd(), // 模型创建
cmd.ControllerCmd(), // 控制器创建
cmd.ServiceCmd(), // 服务类创建
cmd.CommandCmd(), // 命令工具创建
},
}
}
func main() {
if err := Stack().Run(os.Args); err != nil {
panic(err)
}
}