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 {
|
func MustCreateRpcContextFromCli(ctx *cli.Context) *RpcContext {
|
||||||
os := runtime.GOOS
|
os := runtime.GOOS
|
||||||
switch os {
|
switch os {
|
||||||
case "darwin", "windows":
|
case "darwin", "linux", "windows":
|
||||||
default:
|
default:
|
||||||
logx.Must(fmt.Errorf("unexpected os: %s", os))
|
logx.Must(fmt.Errorf("unexpected os: %s", os))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ func Run(arg string) (string, error) {
|
|||||||
goos := runtime.GOOS
|
goos := runtime.GOOS
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
switch goos {
|
switch goos {
|
||||||
case "darwin":
|
case "darwin", "linux":
|
||||||
cmd = exec.Command("sh", "-c", arg)
|
cmd = exec.Command("sh", "-c", arg)
|
||||||
case "windows":
|
case "windows":
|
||||||
cmd = exec.Command("cmd.exe", "/c", arg)
|
cmd = exec.Command("cmd.exe", "/c", arg)
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("unexpected os: %v", goos)
|
return "", fmt.Errorf("unexpected os: %v", goos)
|
||||||
}
|
}
|
||||||
|
|
||||||
dtsout := new(bytes.Buffer)
|
dtsout := new(bytes.Buffer)
|
||||||
stderr := new(bytes.Buffer)
|
stderr := new(bytes.Buffer)
|
||||||
cmd.Stdout = dtsout
|
cmd.Stdout = dtsout
|
||||||
@@ -30,5 +31,6 @@ func Run(arg string) (string, error) {
|
|||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return dtsout.String(), nil
|
return dtsout.String(), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func (g *defaultRpcGenerator) mustGetPackage(dir string) string {
|
|||||||
switch os {
|
switch os {
|
||||||
case "windows":
|
case "windows":
|
||||||
relativePath = filepath.ToSlash(relativePath)
|
relativePath = filepath.ToSlash(relativePath)
|
||||||
case "darwin":
|
case "darwin", "linux":
|
||||||
default:
|
default:
|
||||||
g.Ctx.Fatalln("unexpected os: %s", os)
|
g.Ctx.Fatalln("unexpected os: %s", os)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user