Monday, April 30, 2018

golang - seek help in Go

Go has a lot of useful utilities and packages. Here are the two ways to get information:

1. Check on the official website: https://golang.org/pkg/

    This page has the complete documentation for the Go libraries on it. Say, if i want to know about the fmt package. I can read up on it by visiting: https://golang.org/pkg/fmt/
2. godoc utility 
    This is the utility installed on our local machine. It is setup when we installed the go software. godoc will help us to access any package - including the one which we have written ourselves. 

$ godoc fmt Printf

use 'godoc cmd/fmt' for documentation on the fmt command 

func Printf(format string, a ...interface{}) (n int, err error)

    Printf formats according to a format specifier and writes to standard
    output. It returns the number of bytes written and any write error
    encountered.

$

    
This gives me information on how Printf works. Here, it tells me what the signature of the function is: 
- first is s format string
- it is followed by a number of arguments

It also tells me the return parameter. It returns the number of bytes written and also, error message encountered. 


godoc is especially useful when you are not connected to internet and are seeking information.  Whereas, in online documentation - we can read up right up to the source. This is because Go is a open source language by Google.

No comments:

Post a Comment