Files
go-gin-api/internal/web/controller/gencode_handler/func_initexecute.go
T
2021-03-20 22:05:59 +08:00

34 lines
744 B
Go

package gencode_handler
import (
"bytes"
"fmt"
"os/exec"
"github.com/xinliangnote/go-gin-api/configs"
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
)
func (h *handler) InitExecute() core.HandlerFunc {
return func(c core.Context) {
mysqlConf := configs.Get().MySQL.Read
shellPath := fmt.Sprintf("./scripts/init.sh %s %s %s %s", mysqlConf.Addr, mysqlConf.User, mysqlConf.Pass, mysqlConf.Name)
command := exec.Command("/bin/bash", "-c", shellPath) //初始化 Cmd
// windows 版本
//command := exec.Command("cmd", "/C", shellPath)
var stderr bytes.Buffer
command.Stderr = &stderr
output, err := command.Output()
if err != nil {
c.Payload(stderr.String())
return
}
c.Payload(string(output))
}
}