欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

exported function xxx should have comment or be unexported

程序员文章站 2022-04-29 21:10:24
0x00 问题 exported function xxx should have comment or be unexported。 0x01 解决 https://golang.org/s/style 在这个页面中有提到 Comment SentencesSee https://golang.o ......

0x00 问题

exported function xxx should have comment or be unexported。

exported function xxx should have comment or be unexported

0x01 解决

在这个页面中有提到

comment sentencessee . comments documenting declarations should be full sentences, even if that seems a little redundant. this approach makes them format well when extracted into godoc documentation. comments should begin with the name of the thing being described and end in a period:

记录声明的注释应该是完整的句子,即使这看起来有点多余。这种方法使它们在提取到 godoc 文档时格式良好。注释应以所述物品的名称开始,并以句号结束:

// request represents a request to run a command.
type request struct { ...
// encode writes the json encoding of req to w.
func encode(w io.writer, req *request) { ...

正是如此,golint 才会抛出这条警告,声明你写的代码不符合规范。

符合规范的修改:

exported function xxx should have comment or be unexported

在方法调用中,能看到注释信息:

exported function xxx should have comment or be unexported