在Go语言中,是否可以创建可见的软件包文档?

huangapple go评论86阅读模式
英文:

Is it possible to create visible documentation for package in go?

问题

如何创建可见的Go文档?

要为Go中的任何函数创建文档非常简单,就像这样:

package main

// 文档示例
func DocumentedFunction() bool {
    return true
}

当我调用该函数时,我可以看到该文档:

在Go语言中,是否可以创建可见的软件包文档?

我可以编写包文档,以便从编辑器/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.

huangapple
  • 本文由 发表于 2021年12月15日 19:09:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/70362646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定