should src folder be created in golang go1.17

huangapple go评论81阅读模式
英文:

should src folder be created in golang go1.17

问题

我正在开始学习golang,根据一些文档,它提到$GOPATH默认应该有bin pkg src目录。但是,当我运行go get github.com/astaxie/beedb时,没有创建src文件夹,源代码被放在了$GOPATH/pkg//mod/github.com/astaxie/beedb@v0.0.0-20141221130223-1732292dfde4/目录下。

根据文档,源代码应该在src文件夹中。我正在使用的是golang go1.17版本。新版本是否有所更改,还是我参考的是旧文档?

英文:

I am starting off with golang according to some document it mentions $GOPATH default should have bin pkg src directories.
When a I do go get github.com/astaxie/beedb there no src folder created and the source goes and sits in $GOPATH/pkg//mod/github.com/astaxie/beedb@v0.0.0-20141221130223-1732292dfde4/

according to documentation the it should be in src folder

I am using golang go1.17. Has something changed in newer versions or am I refering old doc.

答案1

得分: 4

你不需要在$GOPATH下创建src文件夹。
使用Go模块后,Go项目不再局限于$GOPATH

不要将项目级别的/src目录与Go以前用于工作区的/src目录混淆,但请注意,“自Go 1.14起,模块支持被认为已经准备好供生产使用,并鼓励所有用户从其他依赖管理系统迁移到模块”1

请查看以下链接:
https://github.com/golang/go/wiki/Modules

英文:

you don't need to create src folder under $GOPATH
With Go modules, Go projects are no longer confined to $GOPATH

Don't confuse the project level /src directory with the /src directory Go used to use for its workspaces, but please note
"Since Go 1.14, module support is considered ready for production use, and all users are encouraged to migrate to modules from other dependency management systems "

please check below links
https://github.com/golang/go/wiki/Modules

答案2

得分: 1

$GOPATH中没有必要手动创建子文件夹。当你运行go get命令时,Go语言会为你处理一切。所以如果没有src文件夹,你可以直接忽略它。

Go Modules(自Go 1.13版本起默认启用)之前,src文件夹主要用于包管理。现在你实际上不再需要它了。

英文:

There is no need to manually create the sub-folders in $GOPATH. When you run go get, go will handle everything for you. So if there is no src folder, you can just leave it.

The src folder was basically for package management before Go Modules (enabled by default since go 1.13). You don't really need this now.

huangapple
  • 本文由 发表于 2021年8月28日 10:01:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/68960807.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定