What are Go Tools?

Something that makes your life much easier as a developer.

김영석
3 min readAug 23, 2022

Go isn’t just about a programming language.

It's also coming bundled with a very useful set of tools.

You can see a list of commands available with “go” binary like following

Last login: Mon Aug 22 10:42:08 on ttys001
➜ ~ go
Go is a tool for managing Go source code.
Usage:go <command> [arguments]The commands are:bug start a bug report
build compile packages and dependencies
clean remove object files and cached files
doc show documentation for package or symbol
env print Go environment information
fix update packages to use new APIs
fmt gofmt (reformat) package sources
generate generate Go files by processing source
get add dependencies to current module and install them
install compile and install packages and dependencies
list list packages or modules
mod module maintenance
work workspace maintenance
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet report likely mistakes in packages
Use "go help <command>" for more information about a command.Additional help topics:buildconstraint build constraints
buildmode build modes
c calling between Go and C
cache build and test caching
environment environment variables
filetype file types
go.mod the go.mod file
gopath GOPATH environment variable
gopath-get legacy GOPATH go get
goproxy module proxy protocol
importpath import path syntax
modules modules, module versions, and more
module-get module-aware go get
module-auth module authentication using go.sum
packages package lists and patterns
private configuration for downloading non-public code
testflag testing flags
testfunc testing functions
vcs controlling version control with GOVCS
Use "go help <topic>" for more information about that topic.➜ ~

Let’s take a look one by one.

First, “bug” command opens up a browser tab with the right place where you can issue an official bug report so that the bug reporting becomes quite handy.

$ go bug
golang bug report
bug report

and the next command is “build”.

As the name suggests, we use this command to build our Go application as a binary executable file.

This command follows this format : go build -o <output path> <packages>

One example would be like this

➜  go-app-one git:(main) ✗ go build -o cmd/demo2/bin/app cmd/demo2/main.go
➜ go-app-one git:(main) ✗ tree cmd/demo2
cmd/demo2
├── bin
│ └── app
└── main.go
1 directory, 2 files
➜ go-app-one git:(main) ✗

the command is outputting the executable file “app” to “cmd/demo2/bin”.

“bin” folder is normally where the executable file is located in Go application project.

and the next is “clean”.

It normally gets run with a flag “-modcache”.

Often times, we need to remove all downloaded packages to refresh up the development environment or do some major upgrades of dependencies. Then, this command helps.

$ go clean -modcache

This removes all downloaded packages in $(go env GOPATH)/pkg/mod directory.

This is what it looks like in the directory before getting cleaned.

➜  go-app-one git:(main) ✗ ls -l /Users/yeongseokkim/go/pkg/mod/
total 0
drwxr-xr-x 4 yeongseokkim staff 128 Aug 23 12:48 cache
drwxr-xr-x 3 yeongseokkim staff 96 Aug 23 12:48 github.com

And after being cleaned..

➜  go-app-one git:(main) ✗ go clean -modcache
➜ go-app-one git:(main) ✗ ls -l /Users/yeongseokkim/go/pkg/mod/
ls: /Users/yeongseokkim/go/pkg/mod/: No such file or directory
➜ go-app-one git:(main) ✗ ls -l /Users/yeongseokkim/go/pkg/
total 0
drwxr-xr-x 4 yeongseokkim staff 128 Aug 25 2021 darwin_amd64
drwxr-xr-x 3 yeongseokkim staff 96 Jun 21 2021 sumdb
➜ go-app-one git:(main) ✗

no more packages there.

the rest of tools will be covered in the next series…

--

--

김영석

I love problem solving and hate repetition of tedious tasks. I like automating, streamlining, optimizing, things.