forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
266 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,83 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
"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/global" | ||
) | ||
|
||
var startAppPath string | ||
var startCmd = &cobra.Command{ | ||
Use: "start", | ||
Short: "启动象传应用引擎", | ||
Long: `启动象传应用引擎`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
defer global.ServiceStop(func() { log.Println("服务已关闭") }) | ||
log.Printf("启动象传应用引擎 v%s mode=%s", global.VERSION, global.Conf.Mode) | ||
log.Printf("应用根目录: %s", global.Conf.Root) | ||
|
||
// 应用目录 | ||
if startAppPath != "" { | ||
global.Conf.Root = startAppPath | ||
global.Conf.RootAPI = filepath.Join(startAppPath, "/apis") | ||
global.Conf.RootFLow = filepath.Join(startAppPath, "/flows") | ||
global.Conf.RootModel = filepath.Join(startAppPath, "/models") | ||
global.Conf.RootPlugin = filepath.Join(startAppPath, "/plugins") | ||
global.Conf.RootTable = filepath.Join(startAppPath, "/tables") | ||
global.Conf.RootChart = filepath.Join(startAppPath, "/charts") | ||
global.Conf.RootScreen = filepath.Join(startAppPath, "/screens") | ||
global.Conf.RootData = filepath.Join(startAppPath, "/data") | ||
|
||
// 重新加载应用 | ||
global.Reload(global.Conf) | ||
defer global.ServiceStop(func() { fmt.Println("服务已关闭") }) | ||
|
||
Boot() | ||
mode := config.Conf.Mode | ||
if mode == "debug" { | ||
mode = color.RedString("调试模式") | ||
} else { | ||
mode = "" | ||
} | ||
|
||
// 启动服务 | ||
for _, api := range gou.APIs { | ||
log.Printf("%s(%d)", api.Name, len(api.HTTP.Paths)) | ||
fmt.Printf(color.GreenString("\n象传应用引擎 v%s %s", global.VERSION, mode)) | ||
|
||
// 加载数据模型 API 等 | ||
global.Load(config.Conf) | ||
|
||
// 打印应用目录信息 | ||
fmt.Printf(color.GreenString("\n应用根目录: %s\n", config.Conf.Root)) | ||
for _, api := range gou.APIs { // API信息 | ||
fmt.Printf(color.CyanString("\n%s(%d)\n", api.Name, len(api.HTTP.Paths))) | ||
for _, p := range api.HTTP.Paths { | ||
log.Println(p.Method, filepath.Join("/api", api.HTTP.Group, p.Path), "\tprocess:", p.Process) | ||
|
||
fmt.Println( | ||
colorMehtod(p.Method), | ||
color.WhiteString(filepath.Join("/api", api.HTTP.Group, p.Path)), | ||
"\tprocess:", p.Process) | ||
} | ||
|
||
} | ||
|
||
domain := global.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前台界面: 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 global.Conf.Mode == "debug" { | ||
if config.Conf.Mode == "debug" { | ||
global.WatchChanges() | ||
} | ||
|
||
global.ServiceStart() | ||
}, | ||
} | ||
|
||
func init() { | ||
startCmd.PersistentFlags().StringVarP(&startAppPath, "app", "a", "", "指定应用目录") | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.