我有少量不相关的文件(它们不是模块或项目的一部分),只是各种草图和注释。
如何一次收集它们,而无需每次明确指定需要编译的内容?
go run .
# _/mnt/library/projects/hck/Go
./listen.go:12:6: main redeclared in this block
previous declaration at ./array.go:7:6
go build .
# _/home/Sharlatan/Projects/hck/Go
./listen.go:12:6: main redeclared in this block
previous declaration at ./array.go:7:6
/array.go/
package main
import (
"fmt"
)
func main() {
var a1 [10]int
a2 := [...]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
fmt.Println(a1)
fmt.Println(a2)
}
/listen.go/
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there!")
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8181", nil)
}
您必须分别指定每个文件。如果您想自动执行此操作,请使用 Make:
或 壳牌:
命令末尾的点 (.) 表示所有内容都属于同一个包,并
main()在编译时给出重复的错误。旧的
Makefile(GNU make)可以解决不应该出现的“问题” - 编译已知未知的不相关文件列表。/生成文件/
链接
go/src/go/基础组件scannertokenparserast