SyntaxStudy
Sign Up
Go Beginner 1 min read

The Go Toolchain

Go ships with a rich set of command-line tools under the `go` command. The most commonly used sub-commands are `go run` for quick execution, `go build` to compile a binary, `go test` to run tests, `go fmt` to format code, and `go vet` to catch common mistakes. All of these work consistently across operating systems. The `gofmt` tool enforces a single canonical formatting style across all Go code. Because there is only one way to format Go, code reviews focus on logic rather than style. Many editors and IDEs integrate gofmt or the more feature-rich `goimports` tool to format code automatically on save. The `go doc` command provides documentation for any package or symbol without leaving the terminal, and `godoc` can serve a local web-based documentation server. Together these tools create a self-contained development environment that reduces the need for external tooling and keeps Go projects consistent and approachable.
Example
// Demonstrate common go tool commands via code comments and a real program.

// $ go build -o myapp .       — compile to binary named "myapp"
// $ go run main.go            — compile and run in one step
// $ go test ./...             — run all tests recursively
// $ go fmt ./...              — format all Go files
// $ go vet ./...              — static analysis
// $ go mod tidy               — add/remove module dependencies
// $ go doc fmt.Println        — show docs for fmt.Println

package main

import (
    "flag"
    "fmt"
    "log"
    "os"
)

func main() {
    // flag demonstrates idiomatic Go CLI argument parsing
    name := flag.String("name", "world", "whom to greet")
    verbose := flag.Bool("v", false, "enable verbose output")
    flag.Parse()

    if *verbose {
        log.SetOutput(os.Stderr)
        log.Printf("Running with name=%q\n", *name)
    }

    fmt.Printf("Hello, %s!\n", *name)
}

// Build and run:
// $ go build -o greet .
// $ ./greet -name=Go -v