One of the contributing factors to Gos popularity is its toolset that supports developer productivity.
Thegocommand has many subcommands and options to work with your go source code.
It lets you build and run programs, manage dependencies, and more besides.
you’re able to access a specific environment variable by specifying the variable name after theenvcommand.
Setting the GOPATH environment is a prerequisite for using some Go packages.
By default, the GOPATH is set to$HOME/goor%USERPROFILE%\godepending on your operating system.
you could change the GOPATH by adding it to the shell configuration file.
The command changes the GOPATH to the specified path.
you’ve got the option to use thegetcommand to download dependencies of your packages.
you could specify a path with thebuildcommand to save the executable to a specified directory.
you could use theinstallcommand to compile and install Go modules.
Like thebuildcommand,installbuilds your program.
But it also adds an executable package to your Go binaries in your$GOPATH/bininstallation directory.
The install command installs the packages in your working directory without additional arguments.
you’ve got the option to specify an optional resource location to install external dependencies.
Youll need to download, update, and view your applications dependencies through your development phase.
Themodcommand provides access to operations on Go modules and dependency management.
Youll need an additional subcommand with the mod command depending on your operation.
You may need to check the packages and modules in your current workspace for various reasons.
Thelistcommand lists all the packages and modules in a specified format.
Run this command to list all packages and modules in a workspace.
The command also lists direct and indirect dependencies in the working directory.
Go Testing Commands
Testing is another important aspect of Go development.
Thetestcommand automates testing packages named by their import paths and outputs a summary of test results.
you might proceed to write your Go tests and run them with thetestcommand.
You dont necessarily need additional commands or arguments to run your Go test.
Without additional parameters, thetestcommand outputs test results in this form.
you might calculate the test coverage of your package with the–coverflag.
The–coverflag returns the percentage of code the tests cover in your package.
They also tend to be more lightweight since they dont involve more complex graphical operations.
One of the intended use cases of Go is to build performant interactive command line applications.
Many popular CLI apps, from Docker to Hugo, are built in Go.
Go provides aflagspackage for building interactive CLI tools like the Go CLI in the standard library.