go run is the standard Go command for compiling and executing a program in one operation. It supports fast iteration without requiring a separate build step. section 1.6 section 2.4.3
Run it from the program’s directory with a Go source file such as main.go. The command compiles the program and immediately displays its output. section 2.4.3
Run a word-counting program
Execute `go run main.go` to process the program. For a file-backed version, create `words.txt`, run the same command, and change the file contents to test the result. Removing the file exercises the program’s error handling. section 2.4.3 section 2.6.5
Listing 2.5 Running the program
$ go run main.go Found 4 words
Shows the command and output for running the initial program. section 2.4.3
Listing 2.28 Running the application on words.txt
$ echo this is four words > words.txt $ go run main.go found 4 words
Shows go run processing a words.txt input file. section 2.6.5
Listing 2.29 Running the application with no input file
$ rm words.txt $ go run main.go 2022/05/05 20:33:39 open words.txt: no such file or directory
Shows the error produced when the expected input file is missing. section 2.6.5
