It's impossible. Here is the source for the command:
for i < len(args) && strings.HasSuffix(args[i], ".go") {
i++
}
files, cmdArgs := args[:i], args[i:]
You can use go installinstead go build. This will put your executable in your folder $GOPATH/bin(I don't like having a binary in the same folder, because sometimes I accidentally add it to git). But it really is not much different.
Another option you might want to consider is rerun. It will automatically recompile and run your code every time the file changes:
rerun path/to/your/project foo.go
Caleb source
share