|
|
|
@ -13,6 +13,10 @@ import (
|
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const goModuleWithoutGoFiles = "command-line-arguments"
|
|
|
|
|
|
|
|
|
|
var errInvalidGoMod = errors.New("invalid go module")
|
|
|
|
|
|
|
|
|
|
// Module contains the relative data of go module,
|
|
|
|
|
// which is the result of the command go list
|
|
|
|
|
type Module struct {
|
|
|
|
@ -23,6 +27,13 @@ type Module struct {
|
|
|
|
|
GoVersion string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Module) validate() error {
|
|
|
|
|
if m.Path == goModuleWithoutGoFiles || m.Dir == "" {
|
|
|
|
|
return errInvalidGoMod
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// projectFromGoMod is used to find the go module and project file path
|
|
|
|
|
// the workDir flag specifies which folder we need to detect based on
|
|
|
|
|
// only valid for go mod project
|
|
|
|
@ -43,6 +54,9 @@ func projectFromGoMod(workDir string) (*ProjectContext, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err := m.validate(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ret ProjectContext
|
|
|
|
|
ret.WorkDir = workDir
|
|
|
|
|