Go - 没有可构建的Go源文件

yet*_*iba 8 build go

大家.我对golang的构建有问题.

细节:

我有一个名为"12"的文件夹,并创建一个名为12_test.go的go源文件.代码如下:

package main

import "fmt"

func main() {
    fmt.Println("Hello world")
}
Run Code Online (Sandbox Code Playgroud)

然后输入"go build 12_test.go".出了点问题:

"go build command-line-arguments: no buildable Go source files in D:\12"
Run Code Online (Sandbox Code Playgroud)

那么,有人可以告诉我为什么吗?感谢并为我可怜的英语道歉.

Sim*_*ead 21

后缀_test在Go中具有特殊含义.这是你为go程序进行测试的地方.构建工具将完全忽略这些......它们与之一起运行go test.

_test从文件名中删除或只是命名test.go.