wujian_develop_tool/api.go

84 lines
1.7 KiB
Go
Raw Normal View History

2022-01-05 20:25:29 +08:00
package main
import (
"fmt"
2022-01-06 20:27:18 +08:00
"os"
"git.icechen.cn/pkg/wdt/template/api/deploy"
"git.icechen.cn/pkg/wdt/template/api/docker/golang"
2022-01-05 20:25:29 +08:00
"github.com/fatih/color"
2022-01-06 20:27:18 +08:00
_ "embed"
2022-01-05 20:25:29 +08:00
"github.com/urfave/cli/v2"
)
2022-01-06 20:27:18 +08:00
// ActionListApi API应用列表
func ActionListApi(c *cli.Context) error {
2022-01-06 00:19:22 +08:00
if err := Init(c); err != nil {
2022-01-05 20:25:29 +08:00
return err
}
color.Green("API应用列表:")
2022-01-06 20:27:18 +08:00
for _, api := range config.HasApi {
2022-01-05 20:25:29 +08:00
color.Green("\t%s", api.Name)
color.Green("\t\t路径:\t%s", api.Root)
color.Green("\t\t类型:\t%s", api.Type)
color.Green("\t\t端口:\t%s", api.Port)
2022-01-06 20:27:18 +08:00
c := color.New(color.Bold, color.FgRed)
2022-01-05 20:25:29 +08:00
c.EnableColor()
_, err := c.Println(healthApi(api))
if err != nil {
return err
}
fmt.Print("\n")
}
return nil
}
2022-01-06 00:19:22 +08:00
// ActionNewApi 创建API应用
func ActionNewApi(c *cli.Context) error {
2022-01-06 20:27:18 +08:00
if err := Init(c); err != nil {
return err
}
appList := c.Args().Slice()
if len(appList) == 0 {
appName := ReadLineWithMessage("请输入要创建的api名称: ")
appList = append(appList, appName)
}
for _, newApp := range appList {
color.Green("正在创建[%s]API应用...", newApp)
if ExistDir("app/api/"+newApp) && !ReadBoolWithMessage("app/api/"+newApp+"目录已存在,是否要覆盖app文件目录(y/n): ") {
return nil
}
err := os.MkdirAll("app/api/"+newApp, os.ModePerm)
if err != nil {
return err
}
aliasName := ReadLineWithMessage("请输入应用的简短描述(别名): ")
err = deploy.GenDeploy(config.Name, newApp, aliasName)
if err != nil {
return err
}
err = golang.GenDockerfile(newApp)
if err != nil {
return err
}
color.Green("[%s]API应用创建成功!!!\n\n", newApp)
}
return nil
}
// ActionFixApi 修复API应用
func ActionFixApi(c *cli.Context) error {
2022-01-06 00:19:22 +08:00
return nil
}