英文:
Go--no buildable Go source file in
问题
大家好。我有一个关于golang构建的问题。
具体情况如下:
我有一个名为"12"的文件夹,并创建了一个名为12_test.go的go源文件。代码如下:
package main
import "fmt"
func main() {
fmt.Println("Hello world")
}
然后输入"go build 12_test.go"。出现了一些问题:
"go build command-line-arguments: no buildable Go source files in D:"
所以,有人能告诉我为什么吗?谢谢,对我的英语不好表示抱歉。
英文:
everyone. I have a problem with golang 's build.
The details:
I have a folder named "12" and creating a go source file named 12_test.go. Codes are below:
package main
import "fmt"
func main() {
fmt.Println("Hello world")
}
.Then typing "go build 12_test.go". Something going wrong:
"go build command-line-arguments: no buildable Go source files in D:"
So,Could someone tell me why? Thanks and apology for my poor English.
答案1
得分: 21
在Go语言中,后缀_test具有特殊的含义。它用于存放你的Go程序的测试代码。构建工具会完全忽略这些文件,它们会通过go test命令来运行。
你可以将文件名中的_test移除,或者直接将其命名为test.go。
英文:
The suffix _test has special meaning in Go. It is where you put tests for your go programs. The build tool will ignore these completely .. they are run with go test.
Remove _test from the file name or just name it test.go.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论