I've seen this discussed in various places, with answers like 'use a cmd/foo, cmd/bar' type folder structure.
This does not work for me.
This works:
$ du -a
8 ./src/cmd/bin1/main.go
8 ./src/cmd/bin1
8 ./src/cmd/bin2/main.go
8 ./src/cmd/bin2
16 ./src/cmd
8 ./src/shared/foo/foo.go
8 ./src/shared/foo
8 ./src/shared
24 ./src
and building it:
go build ./src/cmd/bin2
go build ./src/cmd/bin1
However, I can't figure out what variation on:
go build ./src/...
I might need to build all such binaries in one step.
This layout:
$ du -a
8 ./cmd/bin1/main.go
8 ./cmd/bin1
8 ./cmd/bin2/main.go
8 ./cmd/bin2
16 ./cmd
8 ./src/shared/foo/foo.go
8 ./src/shared/foo
8 ./src/shared
8 ./src
24 .
Seems totally unusable. No combination of go build ...
commands seems to build bin1 or bin2.
The best I can get is go build cmd/bin1/main.go
which gives me a binary called 'main'. Not helpful.
So, specifically and in detail, including the go build
command, that actually builds the individual binaries, how do you do this?
...and why is the default advice that people keep giving to use a top level cmd
folder? How do you build these binaries if you do?
https://github.com/spf13/cobra
you will point it atcmd/main.go
and other command source files will be used as e.g.main doX
main printY
– Plato