Since the introduction of Go in 2009, there have been several changes in how Go developers organize their code and their dependencies. Because of this churn, there’s lots of conflicting advice, and most of it is obsolete. For modern Go development, the rule is simple: you are free to organize your projects as you see fit.
It was meant to be a replacement for C and C++ codebases some things simpler, like concurrency or memory management, with garbage collection and also, to work along with C and C++ codebases, thanks to its C interoperability features.
Out of the box, Go ships with many development tools. You access these tools via the go command.
Basic Go Commands:
go version
- Prints out the version of the Go runtime installedgo env
- Prints out a list of Go environment variablesgo fmt
- Formats given Go filesgo run
- Executes given a Go file/programgo build
- Builds an executable/binary given a Go file/program
GOOS
and GOARCH
environment variables.Go offers a large standard library ready to use that we can use for anything from network connectivity to math, crypto, image processing, filesystem access, and more.
Earlier the GOPATH setup allowed developers to import packages as long as they were in the local Go workspace.
As of Go ~1.13 it’s recommended to use go mod
. With go mod
, source code isn’t required to be a part of the GOPATH
environment variable.
Go doesn’t use a package manager like NPM or Cargo. The Go toolchain provides commands like go get
for fetching external dependencies straight from their remote source control repositories, and go mod
for managing the dependencies of a specific project.
Leave your object oriented brain at home. Embrace the interface.
Learn to do things the Go way, don’t try to force your language idioms into Go.