reactor rpc (#179)
* reactor rpc generation * update flag * update command * update command * update unit test * delete test file * optimize code * update doc * update gen pb * rename target dir * update mysql data type convert rule * add done flag * optimize req/reply parameter * optimize req/reply parameter * remove waste code * remove duplicate parameter * format code * format code * optimize naming * reactor rpcv2 to rpc * remove new line * format code * rename underline to snake * reactor getParentPackage * remove debug log * reactor background
This commit is contained in:
47
tools/goctl/util/ctx/gopath.go
Normal file
47
tools/goctl/util/ctx/gopath.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package ctx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go/build"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
// projectFromGoPath is used to find the main module and project file path
|
||||
// the workDir flag specifies which folder we need to detect based on
|
||||
// only valid for go mod project
|
||||
func projectFromGoPath(workDir string) (*ProjectContext, error) {
|
||||
if len(workDir) == 0 {
|
||||
return nil, errors.New("the work directory is not found")
|
||||
}
|
||||
if _, err := os.Stat(workDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buildContext := build.Default
|
||||
goPath := buildContext.GOPATH
|
||||
goSrc := filepath.Join(goPath, "src")
|
||||
if !util.FileExists(goSrc) {
|
||||
return nil, moduleCheckErr
|
||||
}
|
||||
|
||||
wd, err := filepath.Abs(workDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(wd, goSrc) {
|
||||
return nil, moduleCheckErr
|
||||
}
|
||||
|
||||
projectName := strings.TrimPrefix(wd, goSrc+string(filepath.Separator))
|
||||
return &ProjectContext{
|
||||
WorkDir: workDir,
|
||||
Name: projectName,
|
||||
Path: projectName,
|
||||
Dir: filepath.Join(goSrc, projectName),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user