package main 


我写下面的自我回答的问题,以防止像我这样的人可能再次击中这个障碍。

由于 Nate Finch 注意:


跑步是......真的只是为了用于非常小的程序,通常只需要一个文件。


 go run * .go 
  go run:can not运行* _test.go文件(something_test.go)
 _windows.go 


运行 go 
  go build&& ./<executable> 


I'm a newcomer to Go. I extremely like the language, but I quickly realised that I needed to start dividing my files due to an increase in program size.

go run main.go

didn't work and I hit a barrier for a while, because I had no clue how to get my program working.

Some quick searching lead me to the answer of

go run main.go other.go ..
package main

I write the following self-answered question in order to prevent others like myself who may again hit this barrier.

As Nate Finch notes:

Go run is ... really only meant to be used on very small programs, which generally only need a single file.

go run *.go
go run: cannot run *_test.go files (something_test.go)
_windows.go
go rungo
go build && ./<executable>

这篇关于Golang:通过命令行运行当前目录中的所有.go文件(多文件包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!