提交代码

This commit is contained in:
dandan 2024-10-24 23:03:15 +08:00
parent cc711d9f7a
commit ec23a6a72a
7 changed files with 23 additions and 5 deletions

View File

@ -1,5 +1,7 @@
url: http://127.0.0.1:8066
name: hade
swagger_open: true
dev_fresh: 1

View File

@ -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
},
}

View File

@ -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")

View File

@ -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"
}

View File

@ -36,4 +36,6 @@ type Config interface {
// Load 加载配置到某个对象
Load(key string, val interface{}) error
GetAppName() string
}

View File

@ -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

BIN
hade.exe

Binary file not shown.