英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论