mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
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
This commit is contained in:
parent
0cf4ed46a1
commit
0f97b2019a
@ -1,5 +1,8 @@
|
|||||||
# Change log
|
# Change log
|
||||||
|
|
||||||
|
# 2020-08-29
|
||||||
|
* 新增支持windows生成
|
||||||
|
|
||||||
# 2020-08-27
|
# 2020-08-27
|
||||||
* 新增支持rpc模板生成
|
* 新增支持rpc模板生成
|
||||||
* 新增支持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 {
|
func MustCreateRpcContextFromCli(ctx *cli.Context) *RpcContext {
|
||||||
os := runtime.GOOS
|
os := runtime.GOOS
|
||||||
switch os {
|
switch os {
|
||||||
case "darwin":
|
case "darwin", "windows":
|
||||||
case "windows":
|
|
||||||
logx.Must(fmt.Errorf("windows will support soon"))
|
|
||||||
default:
|
default:
|
||||||
logx.Must(fmt.Errorf("unexpected os: %s", os))
|
logx.Must(fmt.Errorf("unexpected os: %s", os))
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package gen
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||||
@ -41,5 +42,13 @@ func (g *defaultRpcGenerator) mustGetPackage(dir string) string {
|
|||||||
target := g.dirM[dir]
|
target := g.dirM[dir]
|
||||||
projectPath := g.Ctx.ProjectPath
|
projectPath := g.Ctx.ProjectPath
|
||||||
relativePath := strings.TrimPrefix(target, 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
|
return g.Ctx.Module + relativePath
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package gen
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"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/rpc/parser"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||||
)
|
)
|
||||||
@ -119,6 +119,8 @@ func (g *defaultRpcGenerator) genShared() error {
|
|||||||
"types": typeCode,
|
"types": typeCode,
|
||||||
}, filename, true)
|
}, filename, true)
|
||||||
|
|
||||||
|
_, err = exec.LookPath("mockgen")
|
||||||
|
mockGenInstalled := err == nil
|
||||||
for _, service := range file.Service {
|
for _, service := range file.Service {
|
||||||
filename := filepath.Join(g.Ctx.SharedDir, fmt.Sprintf("%smodel.go", service.Name.Lower()))
|
filename := filepath.Join(g.Ctx.SharedDir, fmt.Sprintf("%smodel.go", service.Name.Lower()))
|
||||||
functions, err := g.getFuncs(service)
|
functions, err := g.getFuncs(service)
|
||||||
@ -144,15 +146,13 @@ func (g *defaultRpcGenerator) genShared() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// if mockgen is already installed, it will generate code of gomock for shared files
|
// if mockgen is already installed, it will generate code of gomock for shared files
|
||||||
_, err = exec.LookPath("mockgen")
|
_, err = exec.LookPath("mockgen")
|
||||||
if err != nil {
|
if mockGenInstalled {
|
||||||
g.Ctx.Warning("warning:mockgen is not found")
|
execx.Run(fmt.Sprintf("go generate %s", filename))
|
||||||
} else {
|
|
||||||
execx.Run(fmt.Sprintf("cd %s \ngo generate", g.Ctx.SharedDir))
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user