diff --git a/config/development/app.yaml b/config/development/app.yaml index 11de39e..eda46d7 100644 --- a/config/development/app.yaml +++ b/config/development/app.yaml @@ -1,5 +1,7 @@ url: http://127.0.0.1:8066 +name: hade + swagger_open: true dev_fresh: 1 diff --git a/framework/command/build.go b/framework/command/build.go index 7d38167..545638b 100644 --- a/framework/command/build.go +++ b/framework/command/build.go @@ -3,6 +3,7 @@ package command import ( "fmt" "github.com/Superdanda/hade/framework/cobra" + "github.com/Superdanda/hade/framework/contract" "log" "os/exec" "runtime" @@ -20,13 +21,16 @@ var buildSelfCommand = &cobra.Command{ Use: "self", Short: "编译hade命令", RunE: func(c *cobra.Command, args []string) error { + container := c.GetContainer() + config := container.MustMake(contract.ConfigKey).(contract.Config) + path, err := exec.LookPath("go") if err != nil { log.Fatalln("hade go: 请在Path路径中先安装go") } // 根据系统设置输出文件名 - output := "hade" + output := config.GetAppName() env := []string{} if runtime.GOOS == "windows" { output += ".exe" @@ -46,7 +50,7 @@ var buildSelfCommand = &cobra.Command{ return err } fmt.Println(string(out)) - fmt.Println("编译hade成功") + fmt.Println("编译" + output + "项目成功") return nil }, } diff --git a/framework/command/deploy.go b/framework/command/deploy.go index e065ec6..c0a3ffd 100644 --- a/framework/command/deploy.go +++ b/framework/command/deploy.go @@ -141,7 +141,7 @@ func deployBuildBackend(c *cobra.Command, deployFolder string) error { env := envService.AppEnv() - binFile := "hade" + binFile := configService.GetAppName() // 编译前端 path, err := exec.LookPath("go") diff --git a/framework/command/dev.go b/framework/command/dev.go index 904f456..cdb1d1f 100644 --- a/framework/command/dev.go +++ b/framework/command/dev.go @@ -80,6 +80,7 @@ type Proxy struct { proxyServer *http.Server // proxy的服务 backendPid int // 当前的backend服务的pid frontendPid int // 当前的frontend服务的pid + container framework.Container } // NewProxy 初始化一个Proxy @@ -87,6 +88,7 @@ func NewProxy(c framework.Container) *Proxy { devConfig := initDevConfig(c) return &Proxy{ devConfig: devConfig, + container: c, } } @@ -142,7 +144,8 @@ func (p *Proxy) newProxyReverseProxy(frontend, backend *url.URL) *httputil.Rever func (p *Proxy) rebuildBackend() error { // 重新编译hade fmt.Println("重新编译后端服务") - cmdBuild := exec.Command("./hade", "build", "backend") + config := p.container.MustMake(contract.ConfigKey).(contract.Config) + cmdBuild := exec.Command("./"+config.GetAppName(), "build", "backend") cmdBuild.Stdout = os.Stdout cmdBuild.Stderr = os.Stderr if err := cmdBuild.Start(); err == nil { @@ -179,7 +182,8 @@ func (p *Proxy) restartBackend() error { // 使用命令行启动后端进程 // 根据系统设置输出文件名 - execName := "./hade" + config := p.container.MustMake(contract.ConfigKey).(contract.Config) + execName := "./" + config.GetAppName() if runtime.GOOS == "windows" { execName += ".exe" } diff --git a/framework/contract/config.go b/framework/contract/config.go index 0d311fc..e9c9d83 100644 --- a/framework/contract/config.go +++ b/framework/contract/config.go @@ -36,4 +36,6 @@ type Config interface { // Load 加载配置到某个对象 Load(key string, val interface{}) error + + GetAppName() string } diff --git a/framework/provider/config/service.go b/framework/provider/config/service.go index 6969c77..ed09b5a 100644 --- a/framework/provider/config/service.go +++ b/framework/provider/config/service.go @@ -241,6 +241,12 @@ func (conf *HadeConfig) find(key string) interface{} { return searchMap(conf.confMaps, strings.Split(key, conf.keyDelim)) } +func (conf *HadeConfig) GetAppName() string { + conf.lock.RLock() + defer conf.lock.RUnlock() + return conf.GetString("app.name") +} + func searchMap(source map[string]interface{}, path []string) interface{} { if len(path) == 0 { return source diff --git a/hade.exe b/hade.exe deleted file mode 100644 index b095539..0000000 Binary files a/hade.exe and /dev/null differ