使GO构建适应不同的操作系统

I need to evaluate 'GO' for my requirement of building a CLI tool which should be runnable in different OS s. How is this achieved in the CLI tools such as 'Cloud Foundry CLI'? How does GO handle this adaption into OSs?

Go can build from any OS to any OS. You control the OS and architecture with two environment variables, named GOOS and GOARCH. The former is the operating system, and the latter is the CPU architecture.

Building for 64-bit Linux is set as:

GOARCH=amd64
GOOS=linux

The options for GOARCH are 386, amd64 and arm.

The options for GOOS are darwin, dragonfly, freebsd, linux, netbsd, openbsd, plan9, solaris and windows

There are a few more steps to enabling cross compilation, they are described in more detail here: http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go