Explorar el Código

make goctl work on linux

kevin hace 4 años
padre
commit
431be8ed9d

+ 4 - 0
tools/goctl/Makefile.linux

@@ -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

+ 1 - 1
tools/goctl/rpc/ctx/ctx.go

@@ -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))
 	}

+ 3 - 1
tools/goctl/rpc/execx/execx.go

@@ -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
 }

+ 1 - 1
tools/goctl/rpc/gen/gendir.go

@@ -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)
 	}