是否可以在 go 中为包创建可见文档?
Is it possible to create visible documentation for package in go?
如何创建可见的 Go 文档?
像这样在 go 中为任何函数创建文档很容易:
package main
// documentation example
func DocumentedFunction() bool {
return true
}
而且我在调用该函数时可以看到该文档:
我可以编写包文档吗?editor/IDE 可以看到这些文档吗?我是否必须安装额外的工具来实现包文档的类似行为?
根据 official Go documentation and this link,应该可以像为函数创建文档一样为整个包创建文档:
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.
例如:strings 包:
// Package strings implements simple functions to manipulate UTF-8 encoded strings.
//
// For information about UTF-8 strings in Go, see https://blog.golang.org/strings.
package strings
..
..
rest of the file
所以你基本上只是在 package
关键字上方添加一个普通注释。
如何创建可见的 Go 文档?
像这样在 go 中为任何函数创建文档很容易:
package main
// documentation example
func DocumentedFunction() bool {
return true
}
而且我在调用该函数时可以看到该文档:
我可以编写包文档吗?editor/IDE 可以看到这些文档吗?我是否必须安装额外的工具来实现包文档的类似行为?
根据 official Go documentation and this link,应该可以像为函数创建文档一样为整个包创建文档:
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.
例如:strings 包:
// Package strings implements simple functions to manipulate UTF-8 encoded strings.
//
// For information about UTF-8 strings in Go, see https://blog.golang.org/strings.
package strings
..
..
rest of the file
所以你基本上只是在 package
关键字上方添加一个普通注释。