- Go Systems Programming
- Mihalis Tsoukalos
- 462字
- 2021-07-02 18:07:55
Two useful Go tools
The Go distribution comes with a plethora of tools that can make your life as a programmer easier. The two most useful of them are gofmt and godoc.
The gofmt utility formats Go programs in a given way, which is really important when different people are going to work with the same code for a big project. You can find more information about gofmt at https://golang.org/cmd/gofmt/.
The following is a poorly formatted version of the hw.go program that is hard to read and understand:
$ cat unglyHW.go package main import "fmt" // This is a demonstrative comment! func main() { fmt.Println("Hello World!") }
Processing the previous code, which is saved as unglyHW.go with gofmt, generates the following easy to read and comprehend output:
$ gofmt unglyHW.go package main import "fmt" // This is a demonstrative comment! func main() { fmt.Println("Hello World!") }
Remembering that the gofmt utility does not automatically save the generated output is important, which means that you should either use the -w option followed by a valid filename or redirect the output of gofmt to a new file.
The godoc utility allows you to see the documentation of existing Go packages and functions. You can find more information about godoc at http://godoc.org/golang.org/x/tools/cmd/godoc.
The following screenshot shows the output of the godoc command generated on a Terminal when asked for information about the Println() function of the fmt package:

Another handy feature of godoc is that it can start its own web server and allow you to see its documentation using a web browser:
$ godoc -http=:8080
The following screenshot shows the kind of output you get on a web browser after visiting http://localhost:8080/pkg/ while the previous command is running. You can use any port number you want, provided that it is not already in use:

The most important tool for a programmer is the editor they use for writing the source code. When I am on a Mac, I typically use the TextMate editor, but when I am on a different Unix machine, I prefer vi. Choosing an editor is not an easy task because you are going to spend a lot of time with it. However, any text editor will do the job as long as it does not put any control characters inside the source code files. The following screenshot shows the TextMate editor in action:

- 深入核心的敏捷開發(fā):ThoughtWorks五大關鍵實踐
- Expert C++
- Node.js+Webpack開發(fā)實戰(zhàn)
- Python入門很簡單
- PyTorch自動駕駛視覺感知算法實戰(zhàn)
- Mastering Predictive Analytics with Python
- Arduino家居安全系統構建實戰(zhàn)
- C語言程序設計習題與實驗指導
- Visual C++從入門到精通(第2版)
- Visual Basic語言程序設計基礎(第3版)
- Java自然語言處理(原書第2版)
- MySQL數據庫教程(視頻指導版)
- 跟小樓老師學用Axure RP 9:玩轉產品原型設計
- C/C++程序設計教程
- Java程序性能優(yōu)化實戰(zhàn)