golang 的内部导包路径为什么都是 github ?

golang 的内部导包路径为什么都是 github?

闲着找事干,clone 了 prometheus 的代码 https://github.com/prometheus/prometheus

因为不熟悉 golang,所以看代码的时候,有一些疑问:

图片.png

storage/remote/read_handler.go 中导入了 github.com/prometheus/prometheus/util/gate

可是 util/gate 是 prometheus 这个 project 内部一个模块,而不是第三方的包,为什么这种 『内部模块』也要加 github 前缀呢?

编译的时候,难道还要访问 github 吗?


还有一个子问题,使用 vscode 想看某个东西源码的时候,会使用鼠标左键,但是看 golang 的时候,按了鼠标左键不仅仅会在 vscode 中跳转到源码位置,vscode 还会帮我看到浏览器中的 doc,这太愚蠢了,怎么关闭跳转到浏览器这个功能?

比如我鼠标左键点击 github.com/prometheus/prometheus/util/gate
图片.png
会自动打开浏览器,到 https://pkg.go.dev/github.com/prometheus/prometheus/util/gate?utm_source=gopls
图片.png

我觉得这个功能太愚蠢了,如何关闭?

阅读 3.6k
3 个回答

go语言的包管理就是这么设定的. 如果包名识别成一个url, 就会去clone.

要连接github才行.

内部模块引用出现 github.... 是因为 prometheus 的 module 名定义是这样,只是个名字而已。

module github.com/prometheus/prometheus

go 1.18

开发工具用的不是vscode,在 golang 中是能直接跳转对应内部包的,vscode 应该是把他当成链接了,没有当成包;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题