The godoc utility

The Go distribution comes with a plethora of tools that can simplify your life as a programmer. One of these tools is the godoc utility, which allows you to see the documentation of existing Go functions and packages without needing an internet connection.

The godoc utility can be executed either as a normal command-line application that displays its output on a Terminal window, or as a command-line application that starts a web server. In the latter case, you will need a web browser to look at the Go documentation.

If you type godoc without any command-line parameters, you will get the list of the command-line options supported by godoc.

The first way of executing godoc is similar to using the man(1) command, but for Go functions and packages. So, in order to find out information about the Printf() function of the fmt package, you should execute the following command:

$ godoc fmt Printf  

Similarly, you can find out information about the entire fmt package by running the next command:

$ godoc cmd/fmt

The second way requires executing godoc with the -http parameter:

$ godoc -http=:8001

The numeric value used in the preceding command, 8001, is the port number to which the HTTP server will listen. You can choose any port number that is available provided that you have the right privileges. However, note that port numbers 0-1023 are restricted and can only be used by the root user. Thus, it is better to avoid choosing one of them and to pick something else provided that it is not already in use by a different process.

You can omit the equal sign in the command presented and put a space character in its place. So, the next command is the complete equivalent of the previous one:

$ godoc -http :8001

After that, you should point your web browser to the http://localhost:8001/pkg/ URL in order to get the list of the available Go packages and to browse their documentation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.80.3