代码拉取完成,页面将自动刷新
// Package create /*
package create
import (
"fmt"
"gitee.com/mosache/YFrame/tools/Y/create/apigen"
"gitee.com/mosache/YFrame/tools/Y/create/configgen"
"gitee.com/mosache/YFrame/tools/Y/create/etcgen"
"gitee.com/mosache/YFrame/tools/Y/create/gomodgen"
"gitee.com/mosache/YFrame/tools/Y/create/responsegen"
"gitee.com/mosache/YFrame/tools/Y/create/tplGen"
"gitee.com/mosache/YFrame/tools/Y/utils/cobraErr"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"os"
"os/exec"
)
var Cmd = &cobra.Command{Use: "create",
Long: `create is for create a project.
modName will use as the dir name and in go.mod as module name`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
modName := args[0]
if err := createProjectDir(modName); err != nil {
cobraErr.Err(cmd, err.Error())
}
},
}
func createProjectDir(modName string) error {
if _, err := os.Stat(fmt.Sprintf("./%s", modName)); err != nil && !os.IsNotExist(err) {
return err
} else {
/// create the project dir
if err = os.Mkdir(modName, os.ModePerm); err != nil {
return fmt.Errorf("[create project dir err] : %s", err.Error())
}
if err := os.Chdir(modName); err != nil {
return fmt.Errorf("[cd to project dir err] : %s", err.Error())
}
/// go.mod
if err = gomodgen.CreateGoModFile(modName); err != nil {
return fmt.Errorf("[go.mod create err] : %s", err.Error())
}
/// config
if err = configgen.GenConfig(); err != nil {
return fmt.Errorf("[config config err] : %s", err.Error())
}
/// etc
if err = etcgen.GenEtc(modName); err != nil {
return fmt.Errorf("[create etc err] : %s", err.Error())
}
/// api
if err = apigen.GenApiDir(); err != nil {
return fmt.Errorf("[create api dir err] : %s", err.Error())
}
/// copy .tpl
if err = tplGen.TplGen(); err != nil {
return fmt.Errorf("[copy tpl dir err] : %s", err.Error())
}
/// response
if err = responsegen.GenResponse(); err != nil {
return err
}
///// doc
//if err = docgen.GenDoc(); err != nil {
// return fmt.Errorf("[create doc err] : %s", err.Error())
//}
///// logic
//if err = logicgen.GenLogic(); err != nil {
// return fmt.Errorf("[create logic dir err] : %s", err.Error())
//}
//
///// middleware
//if err = middlewaregen.Gen(); err != nil {
// return fmt.Errorf("[create middleWare dir err] : %s", err.Error())
//}
//
///// router
//if err = routergen.GenRouter(); err != nil {
// return fmt.Errorf("[create router dir err] : %s", err.Error())
//}
///// main.go
//if err = maingen.GenMain(modName); err != nil {
// return fmt.Errorf("[create main file err] : %s", err.Error())
//}
/// fetch deps
if err = fetchDeps(); err != nil {
return fmt.Errorf("[fetch deps err] : %s", err.Error())
}
fmt.Println(aurora.Green(fmt.Sprintf("project [%s] create success...", modName)))
}
return nil
}
func fetchDeps() error {
os.Setenv("GOPRIVATE", "gitee.com/mosache")
os.Setenv("GOPROXY", "https://goproxy.cn")
/// YFrame
if err := exec.Command("go", "get", "-u", "gitee.com/mosache/YFrame").Run(); err != nil {
return err
}
/// go-zero
if err := exec.Command("go", "get", "-u", "github.com/zeromicro/go-zero").Run(); err != nil {
return err
}
if err := exec.Command("go", "mod", "tidy").Run(); err != nil {
return err
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。