Skip to content

Commit

Permalink
Merge pull request #80 from dirtyrain/master
Browse files Browse the repository at this point in the history
Compatible with multiple parameters of GOPATH
  • Loading branch information
UnderTreeTech committed Mar 23, 2021
2 parents f35ed3e + c4dfd13 commit bb4687c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tools/waterdrop/protoc/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/urfave/cli/v2"
Expand All @@ -49,10 +50,26 @@ func doGenerate(ctx *cli.Context, protocCmd string) (err error) {

pwd, _ := os.Getwd()
// case go path
gosrc := filepath.Join(build.Default.GOPATH, "src")
var contectflag string
// gopath setting could be many params, such as
// {
// win : "C:\go\src;D:\go\src"
// linux: "/home/go:/root/go"
// }
if runtime.GOOS == "windows" {
contectflag = ";"
} else {
contectflag = ":"
}
gosrcarr := strings.Split(build.Default.GOPATH, contectflag)
if len(gosrcarr) < 1 {
fmt.Println("gopath directory does not exist, please create it in your GOPATH")
return nil
}
gosrc := filepath.Join(gosrcarr[0], "src")
_, err = os.Stat(gosrc)
if err != nil {
fmt.Println("src directory does not exist, please create it in your GOPATH")
fmt.Printf("src directory does not exist, please create it in your GOPATH: %v", gosrcarr[0])
return nil
}

Expand Down

0 comments on commit bb4687c

Please sign in to comment.