I'm developing a small tool with Go. And recently, I noticed that the tool needs to be invoked from a shell script, because it's using shell function.
Assume my tool is called atool
. So, go build
generates a binary atool
, and my tool has a Go structure as github.com/myaccount/atool
. Now, i want to build atool-cli
binary with go build
, and invoke it from shell script atool
. How can I achieve this?
The only way coming in my mind is change go structure as github.com/myaccuont/atool-cli
. But I don't want to do this because the already announced, and also, the path seems a bit funny name.
To complete the list, go run compiles your application into a temporary folder, and starts that executable binary. When the app exits, it properly cleans up the temporary files.
Much like the previous behaviour of go get , go install places binaries in $GOPATH/bin , or in $GOBIN if set. See the “Setting up your PATH “ section in Installing Go to ensure your PATH is set correctly.
Go Binaries is an open-source server allowing non-Go users to quickly install tools written in Golang, without installing the Go compiler or a package manager — all you need is curl .
Just to make my comment "official":
go build -o atool-cli github.com/you/atool
One way packages structure themselves as a library, and provide main packages is to put their main entrypoints in subdirectories.
You can have a main
package in github.com/myaccount/atool/atool-cli
, which imports github.com/myaccount/atool
and implements func main()
. Some packages with multiple commands even have a /cmd/
directory with multiple cli tools that can be built (see camlistore
as an example)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With