1 Star 0 Fork 0

非空非零/jupiter

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util.go 771 Bytes
一键复制 编辑 原始数据 按行查看 历史
renzhentao 提交于 2021-06-21 15:02 +08:00 . 1
package common
import (
"fmt"
"gitee.com/nonull/eden/pkg/util/xregexp"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// GetModPath ...
func GetModPath(projectPath string) (modPath string) {
dir := filepath.Dir(projectPath)
for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
content, _ := ioutil.ReadFile(filepath.Join(dir, "go.mod"))
mod := xregexp.RegexpReplace(`module\s+(?P<name>[\S]+)`, string(content), "$name")
name := strings.TrimPrefix(filepath.Dir(projectPath), dir)
name = strings.TrimPrefix(name, string(os.PathSeparator))
if name == "" {
return fmt.Sprintf("%s/", mod)
}
return fmt.Sprintf("%s/%s/", mod, name)
}
parent := filepath.Dir(dir)
if dir == parent {
return ""
}
dir = parent
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nonull/eden.git
git@gitee.com:nonull/eden.git
nonull
eden
jupiter
f5e3987f89a2

搜索帮助