Golang comments: Difference between revisions

From wikinotes
(Created page with "<syntaxhighlight lang="go"> // single line comment →‎Multiline * Comment: </syntaxhighlight>")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Comments =
<blockquote>
<syntaxhighlight lang="go">
<syntaxhighlight lang="go">
// single line comment
// single line comment
Line 6: Line 9:
  */
  */
</syntaxhighlight>
</syntaxhighlight>
</blockquote><!-- Comments -->
= Doc Comments =
<blockquote>
Doc-comments are regular comments that preceed a top-level declaration.<br>
The docs recommend that they begin with the name of the function.
It is customary to have a doc-comment above every exported function, constant<br>
and preceding a package statement (any package statement, often there is a <code>doc.go</code> for this comment).
<syntaxhighlight lang="go">
// Words contains a collection of words to be printed.
package words
// Hello prints hello to STDOUT.
// If you'd like to ... etc etc
func Hello() {
    fmt.Println("hello")
}
// Doc-Comments may also preceed a group of declarations
var (
    one = 1
    two = 2
    three = 3
)
</syntaxhighlight>
You can search documentation by by type in your cli
<syntaxhighlight lang="bash">
go doc -all regexp  # print docs for all methods with regexp type in method signature (?)
</syntaxhighlight>
</blockquote><!-- Doc Comments -->

Latest revision as of 03:35, 25 May 2022

Comments

// single line comment

/* Multiline
 * Comment
 */

Doc Comments

Doc-comments are regular comments that preceed a top-level declaration.
The docs recommend that they begin with the name of the function.

It is customary to have a doc-comment above every exported function, constant
and preceding a package statement (any package statement, often there is a doc.go for this comment).

// Words contains a collection of words to be printed.
package words


// Hello prints hello to STDOUT.
// If you'd like to ... etc etc
func Hello() {
    fmt.Println("hello")
}


// Doc-Comments may also preceed a group of declarations
var (
    one = 1
    two = 2
    three = 3
)

You can search documentation by by type in your cli

go doc -all regexp  # print docs for all methods with regexp type in method signature (?)