目录布局和`获取...`for Go语言
假设我有main.go
在目录project/
中,并且具有子目录project/pkg/mydb/code>
main.go使用。
。
要在mydb/
中添加依赖关系,我应该在该subdir mydb/
或Top级项目中运行get ...
目录(project/
)?
另外,main.go
应该居住:直接在project/
或project/src/
中?
Suppose I have main.go
in directory project/
and have subdirectory project/pkg/mydb/
that is used by main.go
.
To add a dependency to my code inside mydb/
I should run go get ...
in that subdir mydb/
or in top-level project directory (project/
)?
Also where main.go
should reside: directly in project/
or in project/src/
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅在模块和软件包的任期内考虑。通常,您的模块将是
项目/
,并且可以由一个或几个软件包组成(project/pkg/mydb
可以是其中之一),只有go模块具有依赖项。 运行
get
in因此,您应该在
项目
main.go
的任何地方 Go Build。或Go Build ./src
(仅在使用GO模块时才适用,因此,如果您在
Project> Project
中有GO.mod。但是,如果您还是应该使用它们)Go only think in term of module and packages. Usually your module would be
project/
and can be composed of one or several packages (project/pkg/mydb
can be one of them)Only go modules have dependencies. So you should run
go get
inproject
main.go
can be wherever you want, it will just change whether you need to rungo build .
orgo build ./src
(This is only applicable if you use go modules, so if you have a go.mod in your
project
. But if you should be using them anyway)