Golang comments: Difference between revisions
From wikinotes
No edit summary |
|||
Line 13: | Line 13: | ||
= Doc Comments = | = Doc Comments = | ||
<blockquote> | <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. | It is customary to have a doc-comment above every exported function. | ||
<syntaxhighlight lang="go"> | <syntaxhighlight lang="go"> | ||
// | // Hello prints hello to STDOUT. | ||
// | // If you'd like to ... etc etc | ||
func Hello() { | func Hello() { | ||
fmt.Println("hello") | fmt.Println("hello") | ||
} | } | ||
</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> | </syntaxhighlight> | ||
</blockquote><!-- Doc Comments --> | </blockquote><!-- Doc Comments --> |
Revision as of 21:12, 23 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.
// Hello prints hello to STDOUT. // If you'd like to ... etc etc func Hello() { fmt.Println("hello") }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 (?)