You cannot, because it's a genuine error.
If you have multiple .go
files in a single package (i.e. package main
) then you can only have one main()
function.
You should be using go build
to build your application into an executable binary. go run
is a quick 'hack' for testing single files, not for complete programs.
Your options:
- Put them in the same package and use
go build
. - Split your 'programs' into separate packages. e.g.
$GOPATH/src/mypkg1
and$GOPATH/src/mypkg2
- Use a scripting language.
I'd also suggest reading How To Write Go Code for how to manage packages.