是否有 API 可以获取使用 go 1.11 模块系统的项目的模块名称?
所以我需要abc.com/a/m从文件中的模块定义module abc.com/a/m中go.mod获取。
截至撰写本文时,我不知道有任何公开的 API。然而,查看源码, Go mod 源文件go mod中有一个非常有用的函数
// ModulePath returns the module path from the gomod file text.
// If it cannot find a module path, it returns an empty string.
// It is tolerant of unrelated problems in the go.mod file.
func ModulePath(mod []byte) string {
//...
}
func main() {
src := `
module github.com/you/hello
require rsc.io/quote v1.5.2
`
mod := ModulePath([]byte(src))
fmt.Println(mod)
}
Run Code Online (Sandbox Code Playgroud)
哪个输出github.com/you/hello
| 归档时间: |
|
| 查看次数: |
1925 次 |
| 最近记录: |