英文:
Difficulty running Go file
问题
我在这个教程上遇到了问题。每次我导航到文件所在的位置并尝试运行"go run populationapi.go"命令时,什么都没有发生。我在我的工作空间中创建了一个名为populationapi.go的文件,并已将其设置为GOPATH变量。我使用的是Windows电脑。它应该放在这三个文件夹(bin、pkg或src)中的哪一个?有关出错原因的任何想法吗?
链接:https://www.programmableweb.com/news/how-to-get-started-google-actions/how-to/2017/01/31?page=4
英文:
I am stuck on this tutorial. Nothing happens every time that I navigate to where my file is located and I try the "go run populationapi.go" step. I made a file populationapi.go in my workspace which I already set as the GOPATH variable. I have a windows computer. Which of the three folders should it be in (bin, pkg, or src)? Any ideas about what's going wrong?
https://www.programmableweb.com/news/how-to-get-started-google-actions/how-to/2017/01/31?page=4
答案1
得分: 1
根据文档的说明,GOPATH
变量应设置为包含bin
、pkg
和src
文件夹的目录。
以下是他们给出的示例目录结构:
GOPATH=/home/user/go
/home/user/go/
src/
foo/
bar/ (包bar中的Go代码)
x.go
quux/ (包main中的Go代码)
y.go
bin/
quux (已安装的命令)
pkg/
linux_amd64/
foo/
bar.a (已安装的包对象)
英文:
According to the documentation, the GOPATH
variable should be set to the folder containing bin
, pkg
, and src
.
Here is the example directory layout they give:
GOPATH=/home/user/go
/home/user/go/
src/
foo/
bar/ (go code in package bar)
x.go
quux/ (go code in package main)
y.go
bin/
quux (installed command)
pkg/
linux_amd64/
foo/
bar.a (installed package object)
答案2
得分: 1
每个 Go 程序都是一个包,它应该位于 "src/package-name/main.go",其中 package-name 是与你的包名相同的目录名。
在你的情况下,应该是 "src/populationapi/main.go"。
或者你可以选择任何包文件名。
然后进入包目录并运行命令 "run main.go"。
在教程中,他们使用了 "ngrok" 实用程序,你需要下载并运行它才能使其工作。
英文:
each go program is a package and it should be in the "src/package-name/main.go"
where as package-name is the directory name which is same as your package name
in your case
it should be "src/populationapi/main.go"
or whatever package file name you choose
then go to the package directory and run the command "run main.go"
in the tutorial they used "ngrok" utility you need to download and run that to make it work
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论