Skip to content

Commit

Permalink
make goctl work on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Aug 30, 2020
1 parent 3c688c3 commit 431be8e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tools/goctl/Makefile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version := $(shell /bin/date "+%Y-%m-%d %H:%M")

build:
GOOS=linux go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" goctl.go && upx goctl
2 changes: 1 addition & 1 deletion tools/goctl/rpc/ctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func MustCreateRpcContext(protoSrc, targetDir, serviceName string, idea bool) *R
func MustCreateRpcContextFromCli(ctx *cli.Context) *RpcContext {
os := runtime.GOOS
switch os {
case "darwin", "windows":
case "darwin", "linux", "windows":
default:
logx.Must(fmt.Errorf("unexpected os: %s", os))
}
Expand Down
4 changes: 3 additions & 1 deletion tools/goctl/rpc/execx/execx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ func Run(arg string) (string, error) {
goos := runtime.GOOS
var cmd *exec.Cmd
switch goos {
case "darwin":
case "darwin", "linux":
cmd = exec.Command("sh", "-c", arg)
case "windows":
cmd = exec.Command("cmd.exe", "/c", arg)
default:
return "", fmt.Errorf("unexpected os: %v", goos)
}

dtsout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
cmd.Stdout = dtsout
Expand All @@ -30,5 +31,6 @@ func Run(arg string) (string, error) {
}
return "", err
}

return dtsout.String(), nil
}
2 changes: 1 addition & 1 deletion tools/goctl/rpc/gen/gendir.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (g *defaultRpcGenerator) mustGetPackage(dir string) string {
switch os {
case "windows":
relativePath = filepath.ToSlash(relativePath)
case "darwin":
case "darwin", "linux":
default:
g.Ctx.Fatalln("unexpected os: %s", os)
}
Expand Down

0 comments on commit 431be8e

Please sign in to comment.