fix windows support
This commit is contained in:
@@ -3,8 +3,10 @@ package generator_handler
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/xinliangnote/go-gin-api/configs"
|
"github.com/xinliangnote/go-gin-api/configs"
|
||||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||||
@@ -14,9 +16,12 @@ type gormExecuteRequest struct {
|
|||||||
Tables string `form:"tables"`
|
Tables string `form:"tables"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const gormgenSh = "./scripts/gormgen.sh"
|
|
||||||
|
|
||||||
func (h *handler) GormExecute() core.HandlerFunc {
|
func (h *handler) GormExecute() core.HandlerFunc {
|
||||||
|
dir, _ := os.Getwd()
|
||||||
|
projectPath := strings.Replace(dir, "\\", "/", -1)
|
||||||
|
gormgenSh := projectPath + "/scripts/gormgen.sh"
|
||||||
|
gormgenBat := projectPath + "/scripts/gormgen.bat"
|
||||||
|
|
||||||
return func(c core.Context) {
|
return func(c core.Context) {
|
||||||
req := new(gormExecuteRequest)
|
req := new(gormExecuteRequest)
|
||||||
if err := c.ShouldBindPostForm(req); err != nil {
|
if err := c.ShouldBindPostForm(req); err != nil {
|
||||||
@@ -26,11 +31,12 @@ func (h *handler) GormExecute() core.HandlerFunc {
|
|||||||
|
|
||||||
mysqlConf := configs.Get().MySQL.Read
|
mysqlConf := configs.Get().MySQL.Read
|
||||||
shellPath := fmt.Sprintf("%s %s %s %s %s %s", gormgenSh, mysqlConf.Addr, mysqlConf.User, mysqlConf.Pass, mysqlConf.Name, req.Tables)
|
shellPath := fmt.Sprintf("%s %s %s %s %s %s", gormgenSh, mysqlConf.Addr, mysqlConf.User, mysqlConf.Pass, mysqlConf.Name, req.Tables)
|
||||||
|
batPath := fmt.Sprintf("%s %s %s %s %s %s", gormgenBat, mysqlConf.Addr, mysqlConf.User, mysqlConf.Pass, mysqlConf.Name, req.Tables)
|
||||||
|
|
||||||
command := new (exec.Cmd)
|
command := new(exec.Cmd)
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
command = exec.Command("cmd", "/C", shellPath)
|
command = exec.Command("cmd", "/C", batPath)
|
||||||
} else {
|
} else {
|
||||||
// runtime.GOOS = linux or darwin
|
// runtime.GOOS = linux or darwin
|
||||||
command = exec.Command("/bin/bash", "-c", shellPath)
|
command = exec.Command("/bin/bash", "-c", shellPath)
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package generator_handler
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
||||||
)
|
)
|
||||||
@@ -13,22 +15,25 @@ type handlerExecuteRequest struct {
|
|||||||
Name string `form:"name"`
|
Name string `form:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlergenSh = "./scripts/handlergen.sh"
|
|
||||||
|
|
||||||
func (h *handler) HandlerExecute() core.HandlerFunc {
|
func (h *handler) HandlerExecute() core.HandlerFunc {
|
||||||
|
dir, _ := os.Getwd()
|
||||||
|
projectPath := strings.Replace(dir, "\\", "/", -1)
|
||||||
|
handlergenSh := projectPath + "/scripts/handlergen.sh"
|
||||||
|
handlergenBat := projectPath + "./scripts/handlergen.bat"
|
||||||
|
|
||||||
return func(c core.Context) {
|
return func(c core.Context) {
|
||||||
req := new(handlerExecuteRequest)
|
req := new(handlerExecuteRequest)
|
||||||
if err := c.ShouldBindPostForm(req); err != nil {
|
if err := c.ShouldBindPostForm(req); err != nil {
|
||||||
c.Payload("参数传递有误")
|
c.Payload("参数传递有误")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
shellPath := fmt.Sprintf("%s %s", handlergenSh, req.Name)
|
shellPath := fmt.Sprintf("%s %s", handlergenSh, req.Name)
|
||||||
|
batPath := fmt.Sprintf("%s %s", handlergenBat, req.Name)
|
||||||
|
|
||||||
command := new (exec.Cmd)
|
command := new(exec.Cmd)
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
command = exec.Command("cmd", "/C", shellPath)
|
command = exec.Command("cmd", "/C", batPath)
|
||||||
} else {
|
} else {
|
||||||
// runtime.GOOS = linux or darwin
|
// runtime.GOOS = linux or darwin
|
||||||
command = exec.Command("/bin/bash", "-c", shellPath)
|
command = exec.Command("/bin/bash", "-c", shellPath)
|
||||||
|
|||||||
45
scripts/gormgen.bat
Normal file
45
scripts/gormgen.bat
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001
|
||||||
|
echo.
|
||||||
|
echo Regenerating file
|
||||||
|
echo.
|
||||||
|
go run -v ./cmd/mysqlmd/main.go -addr %1 -user %2 -pass %3 -name %4 -tables %5
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
echo create curd code :
|
||||||
|
echo.
|
||||||
|
go build -o gormgen ./cmd/gormgen/main.go
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
|
||||||
|
move gormgen $GOPATH/bin
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
|
||||||
|
go generate ./...
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
echo Formatting code
|
||||||
|
echo.
|
||||||
|
go run -v ./cmd/mfmt/main.go
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
echo Done.
|
||||||
10
scripts/gqlgen.bat
Normal file
10
scripts/gqlgen.bat
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001
|
||||||
|
echo.
|
||||||
|
echo Regenerating gqlgen file
|
||||||
|
echo.
|
||||||
|
del internal/graph/generated/generated.go internal/graph/model/generated.go internal/graph/resolvers/generated/generated.go
|
||||||
|
go run -v github.com/99designs/gqlgen $1
|
||||||
|
echo.
|
||||||
|
echo Done.
|
||||||
|
echo.
|
||||||
22
scripts/handlergen.bat
Normal file
22
scripts/handlergen.bat
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001
|
||||||
|
echo.
|
||||||
|
echo Regenerating handler file
|
||||||
|
echo.
|
||||||
|
go run -v ./cmd/handlergen/main.go -handler %1
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
echo Formatting code
|
||||||
|
echo.
|
||||||
|
go run -v ./cmd/mfmt/main.go
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
echo Done.
|
||||||
13
scripts/init.bat
Normal file
13
scripts/init.bat
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001
|
||||||
|
echo.
|
||||||
|
echo Init db
|
||||||
|
echo.
|
||||||
|
go run -v ./cmd/init/db/main.go -addr %1 -user %2 -pass %3 -name %4
|
||||||
|
if %errorlevel% == 1 (
|
||||||
|
echo.
|
||||||
|
echo failed!!!
|
||||||
|
exit 1
|
||||||
|
)
|
||||||
|
echo.
|
||||||
|
echo Done.
|
||||||
8
scripts/swagger.bat
Normal file
8
scripts/swagger.bat
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001
|
||||||
|
echo.
|
||||||
|
echo Regenerating swagger doc
|
||||||
|
echo.
|
||||||
|
go run -v github.com/swaggo/swag/cmd/swag init
|
||||||
|
echo.
|
||||||
|
echo Done.
|
||||||
Reference in New Issue
Block a user