Useful Commands

2 min read


    During our module discussion, we discussed some go commands related to go modules, let's now discuss some other important commands.

    Starting with go fmt, which formats the source code and it's enforced by that language so that we can focus on how our code should work rather than how our code should look.

    $ go fmt

    This might seem a little weird at first especially if you're coming from a javascript or python background like me but frankly, it's quite nice not to worry about linting rules.

    Next, we have go vet which reports likely mistakes in our packages.

    So, if I go ahead and make a mistake in the syntax, and then run go vet.

    It should notify me of the errors.

    $ go vet

    Next, we have go env which simply prints all the go environment information, we'll learn about some of these build-time variables later.

    Lastly, we have go doc which shows documentation for a package or symbol, here's an example of the fmt package.

    $ go doc -src fmt Printf

    Let's use go help command to see what other commands are available.

    $ go help

    As we can see, we have:

    go fix finds Go programs that use old APIs and rewrites them to use newer ones.

    go generate is usually used for code generation.

    go install compiles and installs packages and dependencies.

    go clean is used for cleaning files that are generated by compilers.

    Some other very important commands are go build and go test but we will learn about them in detail later in the course.

    © 2024 Karan Pratap Singh