You should use standard // comments because this is what the official documentation tool called godoc will use to generate documentation for your go code. You can have a look at this post from the official golang blog about it: http://blog.golang.org/godoc-documenting-go-code

I also found this quite interesting: https://godoc.org/github.com/natefinch/godocgo

Answer from Jery on Stack Overflow
🌐
Go Programming Language
go.dev › doc
Documentation - The Go Programming Language
$ go install golang.org/x/website/tour@latest · This will place the tour binary in your GOPATH's bin directory. A document that gives tips for writing clear, idiomatic Go code. A must read for any new Go programmer. It augments the tour and the language specification, both of which should be read first.
🌐
Go
go.dev › blog › godoc
Godoc: documenting Go code - The Go Programming Language
March 31, 2011 - The convention is simple: to document a type, variable, constant, function, or even a package, write a regular comment directly preceding its declaration, with no intervening blank line. Godoc will then present that comment as text alongside the item it documents.
🌐
YourBasic
yourbasic.org › golang › package-documentation
Package documentation · YourBasic Go
To document a function, type, constant, variable, or even a complete package, write a regular comment directly preceding its declaration, with no blank line in between. For example, this is the documentation for the fmt.Println function:
🌐
Go
go.dev › doc › effective_go
Effective Go - The Go Programming Language
This means a user of the data structure can create one with new and get right to work. For example, the documentation for bytes.Buffer states that "the zero value for Buffer is an empty buffer ready to use." Similarly, sync.Mutex does not have an explicit constructor or Init method.
🌐
Go by Example
gobyexample.com
Go by Example
Go is an open source programming language designed for building scalable, secure and reliable software. Please read the official documentation to learn more. Go by Example is a hands-on introduction to Go using annotated example programs.
🌐
Medium
nirdoshgautam.medium.com › a-guide-to-effective-go-documentation-952f346d073f
A Guide to Effective Go Documentation | by Nirdosh Gautam | Medium
March 11, 2024 - Let’s look into the comments in this sample code and what the generated documentation looks like: ... The title or short description should be the first comment for the package without any new lines between the comment and the package definition. Long description Starts after topic sentences after a new line. Can contain as many paragraphs and sections as we want. Sub-sections/headings Starts with “#” and is displayed as a sub-heading · Code Examples If we indent anything in the description section, it is displayed inside a block, whether it is code or not.
🌐
Golang Docs
golangdocs.com
Golang Docs - Golang Tutorials
Go, often referred to as Golang, is a modern programming language developed by Google. Thanks to its efficiency, simplicity, and robust support for concurrency, Go has become a popular choice for developing scalable web servers, cloud services, and command-line tools.
🌐
Go Programming Language
tip.golang.org › doc › comment
Go Doc Comments - The Go Programming Language
Directive comments such as //go:generate are not considered part of a doc comment and are omitted from rendered documentation. Gofmt moves directive comments to the end of the doc comment, preceded by a blank line. For example:
Find elsewhere
🌐
GitHub
github.com › amalmadhu06 › godoc-example
GitHub - amalmadhu06/godoc-example: How to use godoc for documenting your Go packages? Explained with examples · GitHub
How to use godoc for documenting your Go packages? Explained with examples - amalmadhu06/godoc-example
Author   amalmadhu06
🌐
Go
go.dev › blog › examples
Testable Examples in Go - The Go Programming Language
May 7, 2015 - $ go test -v === RUN TestString --- PASS: TestString (0.00s) PASS ok golang.org/x/example/hello/reverse 0.110s · Examples without output comments are useful for demonstrating code that cannot run as unit tests, such as that which accesses the network, while guaranteeing the example at least compiles. Godoc uses a naming convention to associate an example function with a package-level identifier. func ExampleFoo() // documents the Foo function or type func ExampleBar_Qux() // documents the Qux method of type Bar func Example() // documents the package as a whole
🌐
Go
go.dev › doc › tutorial › getting-started
Tutorial: Get started with Go - The Go Programming Language
$ go mod init example/hello go: creating new go.mod: module example/hello
🌐
Go
go.dev › src › go › doc › example.go
example function doc string
271 for _, c := range file.Comments { 272 if body.Pos() <= c.Pos() && c.End() <= body.End() { 273 comments = append(comments, c) 274 } 275 } 276 277 // Strip the "Output:" or "Unordered output:" comment and adjust body 278 // end position. 279 body, comments = stripOutputComment(body, comments) 280 281 // Include documentation belonging to dependent declarations.
🌐
Go
go.dev › ref › spec
The Go Programming Language Specification - The Go Programming Language
Source code is Unicode text encoded in UTF-8. The text is not canonicalized, so a single accented code point is distinct from the same character constructed from combining an accent and a letter; those are treated as two code points. For simplicity, this document will use the unqualified term character to refer to a Unicode code point in the source text.
🌐
GitHub
gist.github.com › 1089368
Godoc example · GitHub
Godoc example. GitHub Gist: instantly share code, notes, and snippets.
🌐
7-Zip Documentation
documentation.help › Golang › go_doc.htm
doc - The Go Programming Language - Golang Documentation
type Example struct { Name string // name of the item being exemplified Doc string // example function doc string Code ast.Node Comments []*ast.CommentGroup Output string // expected output }
🌐
Go Programming Language
go.dev › doc › comment
Go Doc Comments - The Go Programming Language
A span of unindented non-blank lines defines link targets when every line is of the form “[Text]: URL”. In other text in the same doc comment, “[Text]” represents a link to URL using the given text—in HTML, <a href=“URL”>Text</a>. For example: // Package json implements encoding and decoding of JSON as defined in // [RFC 7159]. The mapping between JSON and Go values is described // in the documentation for the Marshal and Unmarshal functions. // // For an introduction to this package, see the article // “[JSON and Go].” // // [RFC 7159]: https://tools.ietf.org/html/rfc7159 // [JSON and Go]: https://golang.org/doc/articles/json_and_go.html package json
🌐
ITNEXT
itnext.io › documenting-go-code-with-gonotes-68422ddcf7ad
Documenting Go Code with Gonotes. When writing code, an abundance of… | by pokstad | ITNEXT
September 7, 2018 - Here are a few examples of godoc notes from the Go standard library: TODO(mundaym): merge with case 24. TODO(rogpeppe): re-enable this test in https://go-review.googlesource.com/#/c/5910/ TODO(rsc): Decide which tests are enabled by default.
🌐
The Go Programming Language
tip.golang.org › src › cmd › go › internal › doc › doc.go
- The Go Programming Language
194 func do(ctx context.Context, writer io.Writer, flagSet *flag.FlagSet, args []string) (err error) { 195 flagSet.Usage = func() { usage(flagSet) } 196 unexported = false 197 matchCase = false 198 flagSet.StringVar(&chdir, "C", "", "change to `dir` before running command") 199 flagSet.BoolVar(&unexported, "u", false, "show unexported symbols as well as exported") 200 flagSet.BoolVar(&matchCase, "c", false, "symbol matching honors case (paths not affected)") 201 flagSet.BoolVar(&showAll, "all", false, "show all documentation for package") 202 flagSet.BoolVar(&showEx, "ex", false, "show executa