forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.go
99 lines (82 loc) · 2.73 KB
/
start.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
package cmd
import (
"fmt"
"path/filepath"
"strings"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/yaoapp/gou"
"github.com/yaoapp/xiang/config"
"github.com/yaoapp/xiang/engine"
"github.com/yaoapp/xiang/service"
"github.com/yaoapp/xiang/share"
)
var startCmd = &cobra.Command{
Use: "start",
Short: "启动象传应用引擎",
Long: `启动象传应用引擎`,
Run: func(cmd *cobra.Command, args []string) {
defer service.Stop(func() { fmt.Println("服务已关闭") })
Boot()
mode := config.Conf.Mode
if mode == "debug" {
mode = color.RedString("调试模式")
} else {
mode = ""
}
fmt.Printf(color.GreenString("\n象传应用引擎 v%s %s", share.VERSION, mode))
// 加载数据模型 API 等
engine.Load(config.Conf)
// 打印应用目录信息
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", config.Conf.RootData))
fmt.Printf(color.GreenString("\n数据存储引擎: %s", share.App.Storage.Default))
fmt.Printf(color.WhiteString("\n---------------------------------\n\n"))
fmt.Printf(color.GreenString("\n已注册API"))
fmt.Printf(color.WhiteString("\n---------------------------------"))
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)
}
}
domain := share.DOMAIN
if domain == "*.iqka.com" {
domain = "local.iqka.com"
}
port := fmt.Sprintf(":%d", config.Conf.Service.Port)
if port == ":80" {
port = ""
}
fmt.Printf(color.GreenString("\n\n访问入口"))
fmt.Printf(color.WhiteString("\n---------------------------------"))
fmt.Printf(color.GreenString("\n前台界面: http://%s%s/\n", domain, port))
fmt.Printf(color.GreenString("管理后台: http://%s%s/xiang/login\n", domain, port))
fmt.Printf(color.GreenString("API 接口: http://%s%s/api\n", domain, port))
fmt.Printf(color.GreenString("跨域访问: %s\n\n", strings.Join(config.Conf.Service.Allow, ",")))
// 调试模式
if config.Conf.Mode == "debug" {
service.Watch(config.Conf)
}
service.Start()
},
}
func colorMehtod(method string) string {
method = strings.ToUpper(method)
switch method {
case "GET":
return color.GreenString("GET")
case "POST":
return color.YellowString("POST")
default:
return color.WhiteString(method)
}
}