英文:
Can someone please dumb down go mod init for me?
问题
我正在尝试使用Go的模块功能来理解它们的工作原理。我已经阅读了文档,甚至复制了完全相同的过程,但是在导入本地模块时出现了一些问题。文件树的结构如下:
src
|
main -> main.go
|
pkg -> pkg.go
src文件夹下有两个文件夹,main和pkg。
我的问题是在哪里应该调用go mod init
命令,以及应该如何命名它。这个问题困扰了我一段时间了。
英文:
I am trying to use the module capabilities of go to understand how they work. I have read the documentation and even replicated the exact process and for some reason the import of local modules. The file tree is like this
src
|
main -> main.go
|
pkg -> pkg.go
The src folder has two folders main and pkg.
My question is where should I call go mod init
and how should I name it. This has been confusing me for a while now.
答案1
得分: 2
我将使用Windows路径,因为这是我使用的系统。首先,在某个地方创建一个新文件夹,例如C:\north
。然后进入该目录,并输入以下内容:
go mod init north
然后创建C:\north\north.go
文件:
package north
const Direction = "north"
接下来创建C:\north\north\north.go
文件:
package main
import "north"
func main() {
println(north.Direction)
}
英文:
I will use Windows paths, as that's what I use. First, make a new folder somewhere, for example C:\north
. They go to that directory, and enter this:
go mod init north
Then make C:\north\north.go
:
package north
const Direction = "north"
Then make C:\north\north\north.go
:
package main
import "north"
func main() {
println(north.Direction)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论