rpc generation support windows (#28)

* add execute files

* add protoc-osx

* add rpc generation

* add rpc generation

* add: rpc template generation

* update usage

* fixed env prepare for project in go path

* optimize gomod cache

* add README.md

* format error

* reactor templatex.go

* remove waste code

* update project.go & README.md

* update project.go & README.md

* rpc generation supports windows
master
Keson 4 years ago committed by GitHub
parent 0cf4ed46a1
commit 0f97b2019a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,8 @@
# Change log
# 2020-08-29
* 新增支持windows生成
# 2020-08-27
* 新增支持rpc模板生成
* 新增支持rpc服务生成

@ -134,9 +134,6 @@ OPTIONS:
的标识,请注意不要将也写业务性代码写在里面。
# 下一步规划
* 尽快支持windows端rpc生成

@ -88,9 +88,7 @@ func MustCreateRpcContext(protoSrc, targetDir, sharedDir, serviceName string, id
func MustCreateRpcContextFromCli(ctx *cli.Context) *RpcContext {
os := runtime.GOOS
switch os {
case "darwin":
case "windows":
logx.Must(fmt.Errorf("windows will support soon"))
case "darwin", "windows":
default:
logx.Must(fmt.Errorf("unexpected os: %s", os))
}

@ -2,6 +2,7 @@ package gen
import (
"path/filepath"
"runtime"
"strings"
"github.com/tal-tech/go-zero/tools/goctl/util"
@ -41,5 +42,13 @@ func (g *defaultRpcGenerator) mustGetPackage(dir string) string {
target := g.dirM[dir]
projectPath := g.Ctx.ProjectPath
relativePath := strings.TrimPrefix(target, projectPath)
os := runtime.GOOS
switch os {
case "windows":
relativePath = filepath.ToSlash(relativePath)
case "darwin":
default:
g.Ctx.Fatalln("unexpected os: %s", os)
}
return g.Ctx.Module + relativePath
}

@ -2,12 +2,12 @@ package gen
import (
"fmt"
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
"github.com/tal-tech/go-zero/tools/goctl/util"
)
@ -119,6 +119,8 @@ func (g *defaultRpcGenerator) genShared() error {
"types": typeCode,
}, filename, true)
_, err = exec.LookPath("mockgen")
mockGenInstalled := err == nil
for _, service := range file.Service {
filename := filepath.Join(g.Ctx.SharedDir, fmt.Sprintf("%smodel.go", service.Name.Lower()))
functions, err := g.getFuncs(service)
@ -144,15 +146,13 @@ func (g *defaultRpcGenerator) genShared() error {
if err != nil {
return err
}
// if mockgen is already installed, it will generate code of gomock for shared files
_, err = exec.LookPath("mockgen")
if mockGenInstalled {
execx.Run(fmt.Sprintf("go generate %s", filename))
}
}
// if mockgen is already installed, it will generate code of gomock for shared files
_, err = exec.LookPath("mockgen")
if err != nil {
g.Ctx.Warning("warning:mockgen is not found")
} else {
execx.Run(fmt.Sprintf("cd %s \ngo generate", g.Ctx.SharedDir))
}
return nil
}

Loading…
Cancel
Save