make goctl work on linux
This commit is contained in:
4
tools/goctl/Makefile.linux
Normal file
4
tools/goctl/Makefile.linux
Normal file
@@ -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
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -30,5 +31,6 @@ func Run(arg string) (string, error) {
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
return dtsout.String(), nil
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user