英文:
Is it possible to create visible documentation for package in go?
问题
如何创建可见的Go文档?
要为Go中的任何函数创建文档非常简单,就像这样:
package main
// 文档示例
func DocumentedFunction() bool {
return true
}
当我调用该函数时,我可以看到该文档:
我可以编写包文档,以便从编辑器/IDE中看到吗?我需要安装其他工具来实现类似的包文档行为吗?
英文:
How to create visible Go documentation?
That is easy to create documentation for any function in go like that:
package main
// documentation example
func DocumentedFunction() bool {
return true
}
And i can see that documentation when i call that function:
![alt text](https://raw.githubusercontent.com/Dancheg97/Dancheg97/main/godoc.png "Title")
Can i write package documentation, that will be visible from editor/IDE? Do i have to install additional tools to achieve similar behaviour for package documentation?
答案1
得分: 4
根据官方Go文档和此链接,可以通过与函数相同的方式为整个包创建文档:
要为函数、类型、常量、变量甚至整个包编写文档,请在其声明之前直接编写一个常规注释,注释前后没有空行。
例如: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
..
..
文件的其余部分
因此,你只需在package
关键字上方添加一个普通注释即可。
英文:
According to the official Go documentation and this link, it should be possible to create documentation for an entire package the same way you would do it for a function:
> 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: the strings package:
// 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
So you basically just add a normal comment above the package
keyword.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论