1 Star 0 Fork 0

mosache/go-zero

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
context.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
Keson 提交于 2020-11-05 14:12 +08:00 . reactor rpc (#179)
package ctx
import (
"errors"
"path/filepath"
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
)
var moduleCheckErr = errors.New("the work directory must be found in the go mod or the $GOPATH")
type (
ProjectContext struct {
WorkDir string
// Name is the root name of the project
// eg: go-zero、greet
Name string
// Path identifies which module a project belongs to, which is module value if it's a go mod project,
// or else it is the root name of the project, eg: github.com/tal-tech/go-zero、greet
Path string
// Dir is the path of the project, eg: /Users/keson/goland/go/go-zero、/Users/keson/go/src/greet
Dir string
}
)
// Prepare checks the project which module belongs to,and returns the path and module.
// workDir parameter is the directory of the source of generating code,
// where can be found the project path and the project module,
func Prepare(workDir string) (*ProjectContext, error) {
ctx, err := background(workDir)
if err == nil {
return ctx, nil
}
name := filepath.Base(workDir)
_, err = execx.Run("go mod init "+name, workDir)
if err != nil {
return nil, err
}
return background(workDir)
}
func background(workDir string) (*ProjectContext, error) {
isGoMod, err := IsGoMod(workDir)
if err != nil {
return nil, err
}
if isGoMod {
return projectFromGoMod(workDir)
}
return projectFromGoPath(workDir)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mosache/go-zero.git
git@gitee.com:mosache/go-zero.git
mosache
go-zero
go-zero
dfb45c801a6c

搜索帮助