The go -x Option
It has been a long time since I wrote about Go, so here we are!
What is go -x?
Link to heading
The -x flag tells the Go command to print the commands it runs.
Normally go build, go test, or go run work silently. With -x, you see every step the toolchain takes.
Example Link to heading
$ go build -x hello.go
Where hello.go is:
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World!")
}
The generated output will be similar to the following:
WORK=/var/folders/sk/ltk8cnw50lzdtr2hxcj5sv2m0000gn/T/go-build1569887254
/Users/mtsouk/Library/Caches/go-build/4d/4dd8e281d8991b42b693dc0666cd07e3cb1a39a5a73d1833c8d1f9f2fd135cda-d/hw
Hello World!
When is it useful? Link to heading
- Understanding what the Go tool is actually doing
- Debugging failed builds
- Seeing the exact compiler and linker commands
Related flag Link to heading
-n Prints the commands but does not run them.
Mastering Go, 4th edition Link to heading
Whether you are a seasoned Gopher or leveling up your skills, Mastering Go is an excellent companion. You can get the book on Packt, Amazon.com, all other Amazon web sites as well as on other book stores.
Practical Systems Programming in Go Link to heading
You can purchase Practical Systems Programming in Go from the following links:
All code from the book is available in the official GitHub repository.