Go Concepts - Documentation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 39: Line 39:


==Package Identifier Documentation==
==Package Identifier Documentation==
Add a "//" comment before the exported identifier (function, type, etc).
Example:
<pre>
// This function pains all its arguments blue
fun Blue(s string) string {
...
}
</pre>
<tt>go doc</tt> will work as follows:
<pre>
go doc blue Blue
func Blue(s string) string
    This function paints all its arguments blue
</pre>

Revision as of 01:57, 2 April 2016

Internal

Overview

Go generates in-line documentation for symbols in packages, via the go doc command.

Reading Documentation

To read the package summary:

go doc <package-name>

Example:

go doc fmt

To get the documentation for a package identifier (function name, type, etc):

go doc <package-name> <identifier>

Example:

go doc fmt Println

Writing Documentation

Package-Level Documentation

Package Identifier Documentation

Add a "//" comment before the exported identifier (function, type, etc).

Example:

// This function pains all its arguments blue
fun Blue(s string) string {
...
}

go doc will work as follows:

go doc blue Blue
func Blue(s string) string
    This function paints all its arguments blue