Skip to content

Commit

Permalink
规范服务启动命令输出
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 9, 2022
1 parent ba82976 commit 2a98f82
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ var langs = map[string]string{
"Show version": "显示当前版本号",
"Development mode": "使用开发模式启动",
"Enabled unstable features": "启用内测功能",
"Fatal: %s": "失败: %s",
"Service stopped": "服务已关闭",
"API": " API接口",
"API List": "API列表",
"Root": "应用目录",
"Frontend": "前台地址",
"Dashboard": "管理后台",
}

// L 多语言切换
Expand Down
83 changes: 42 additions & 41 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,62 @@ var startCmd = &cobra.Command{
Short: L("Start Engine"),
Long: L("Start Engine"),
Run: func(cmd *cobra.Command, args []string) {
defer service.Stop(func() { fmt.Println("服务已关闭") })
defer service.Stop(func() { fmt.Println(L("Service stopped")) })
Boot()

if startDebug { // 强制 debug 模式启动
config.Development()
}

mode := config.Conf.Mode
if mode == "debug" {
mode = color.RedString("调试模式\n")
} else {
mode = "\n"
}

err := engine.Load(config.Conf) // 加载脚本等
if err != nil {
fmt.Printf(color.RedString("启动失败: %s\n", err.Error()))
fmt.Printf(color.RedString(L("Fatal: %s"), err.Error()))
os.Exit(1)
}
port := fmt.Sprintf(":%d", config.Conf.Port)
if port == ":80" {
port = ""
}

host := config.Conf.Host
if host == "0.0.0.0" {
host = "127.0.0.1"
}

// 打印应用目录信息
fmt.Printf(color.GreenString("象传应用引擎 v%s %s", share.VERSION, mode))
fmt.Printf(color.WhiteString("\n---------------------------------"))
fmt.Printf(color.GreenString("\n应用名称: %s v%s", share.App.Name, share.App.Version))
fmt.Printf(color.GreenString("\n应用根目录: %s", config.Conf.Root))
fmt.Printf(color.GreenString("\n数据存储引擎: %s", share.App.Storage.Default))
fmt.Printf(color.WhiteString("\n---------------------------------\n\n"))
if mode == "development" {
fmt.Println(color.WhiteString("\n---------------------------------"))
fmt.Println(color.WhiteString(L("API List")))
fmt.Println(color.WhiteString("---------------------------------"))

fmt.Printf(color.GreenString("\n已注册API"))
fmt.Printf(color.WhiteString("\n---------------------------------"))
for _, api := range gou.APIs { // API信息
if len(api.HTTP.Paths) <= 0 {
continue
}

for _, api := range gou.APIs { // API信息
if len(api.HTTP.Paths) <= 0 {
continue
}
fmt.Printf(color.CyanString("\n%s(%d)\n", api.Name, len(api.HTTP.Paths)))
for _, p := range api.HTTP.Paths {
fmt.Println(
colorMehtod(p.Method),
color.WhiteString(filepath.Join("/api", api.HTTP.Group, p.Path)),
"\tprocess:", p.Process)
}

fmt.Printf(color.CyanString("\n%s(%d)\n", api.Name, len(api.HTTP.Paths)))
for _, p := range api.HTTP.Paths {
fmt.Println(
colorMehtod(p.Method),
color.WhiteString(filepath.Join("/api", api.HTTP.Group, p.Path)),
"\tprocess:", p.Process)
}

}

port := fmt.Sprintf(":%d", config.Conf.Port)
if port == ":80" {
port = ""
fmt.Println(color.WhiteString("\n---------------------------------"))
fmt.Println(color.WhiteString(share.App.Name), color.WhiteString(share.App.Version), mode)
fmt.Println(color.WhiteString("---------------------------------"))
if !share.BUILDIN {
root, _ := filepath.Abs(config.Conf.Root)
fmt.Println(color.WhiteString(L("Root")), color.GreenString(" %s", root))
}

fmt.Printf(color.GreenString("\n\n象传应用引擎"))
fmt.Printf(color.WhiteString("\n---------------------------------"))
fmt.Printf(color.GreenString("\n前台界面: http://%s%s/\n", "127.0.0.1", port))
fmt.Printf(color.GreenString("管理后台: http://%s%s/xiang/login/admin\n", "127.0.0.1", port))
fmt.Printf(color.GreenString("API 接口: http://%s%s/api\n", "127.0.0.1", port))
// fmt.Printf(color.GreenString("跨域访问: %s\n\n", strings.Join(config.Conf.Service.Allow, ",")))
fmt.Println(color.WhiteString(L("Frontend")), color.GreenString(" http://%s%s/", host, port))
fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" http://%s%s/xiang/login/admin", host, port))
fmt.Println(color.WhiteString(L("API")), color.GreenString(" http://%s%s/api", host, port))
fmt.Println("")

// 调试模式
if config.Conf.Mode == "debug" {
Expand All @@ -89,13 +88,15 @@ var startCmd = &cobra.Command{
// 启用内测功能
if startAlpha {
for _, srv := range gou.Servers {
fmt.Printf(color.GreenString("%s服务", srv.Name))
fmt.Printf(color.WhiteString("\n---------------------------------"))
fmt.Printf(color.GreenString("\nHost: %s://%s", srv.Protocol, srv.Host))
fmt.Printf(color.GreenString("\nPort: %s\n\n", srv.Port))
fmt.Println(color.WhiteString("\n---------------------------------"))
fmt.Println(color.WhiteString(srv.Name))
fmt.Println(color.WhiteString("---------------------------------"))
fmt.Println(color.GreenString("Host: %s://%s", srv.Protocol, srv.Host))
fmt.Println(color.GreenString("Port: %s\n\n", srv.Port))
go srv.Start()
}
}

service.Start()
},
}
Expand Down

0 comments on commit 2a98f82

Please sign in to comment.