go-zero/tools/goctl/util/ctx/modcheck.go
Fyn e62870e268
feat(goctl): go work multi-module support (#1800)
* feat(goctl): go work multi-module support

Resolve: #1793

* chore: print log when getting project ctx fails
2022-04-18 20:36:41 +08:00

26 lines
547 B
Go

package ctx
import (
"errors"
"os"
"github.com/zeromicro/go-zero/tools/goctl/rpc/execx"
)
// IsGoMod is used to determine whether workDir is a go module project through command `go list -json -m`
func IsGoMod(workDir string) (bool, error) {
if len(workDir) == 0 {
return false, errors.New("the work directory is not found")
}
if _, err := os.Stat(workDir); err != nil {
return false, err
}
data, err := execx.Run("go list -m -f '{{.GoMod}}'", workDir)
if err != nil || len(data) == 0 {
return false, nil
}
return true, nil
}