卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章33910本站已运行390

Go Doc 意外地缩进/分组函数。是什么原因造成的?

go doc 意外地缩进/分组函数。是什么原因造成的?

问题内容

go doc 正在缩进/创建一个组,而我没有故意告诉它。

这是我的浏览器的屏幕截图,显示了该问题。四个 parse 函数不应缩进:

是什么导致了这种行为?

我尝试在 go docs 中搜索缩进/小节/分组,但除了功能请求之外我没有找到任何内容。我确信我的问题的答案在文档中的某个地方,但我找不到它,因为我没有正确的词汇。

我对 go 和 go doc 比较陌生,所以我假设答案很简单,但我忽略了。

这是我的代码的摘录。如果我需要分享更多代码,请告诉我。

status.go

package synop

// status codes returned when parsing blocks.
type status int64

const (
    valid status = iota
    no_data
    // code omitted
)

// other functions omitted

cloudwind_block.go

package synop

import (
    "strings"
)

/*
Extract cloud cover from the cloud-wind block, Cxxxx.
Cloud, C, is the first digit of the block. Cloud over is given in [okta]:
*/
func ParseCloud(block string) (okta int, s Status) {
    slice := [2]int{0, 1}
    return parseIfValid(block, slice, str2int)
}

/*
Extract wind direction from from the cloud-wind block, xDDxxx.
Direction, DD, are the second and third digits.
*/
func ParseDir(block string) (dir string, s Status) {
    slice := [2]int{1, 3}
    return parseIfValid(block, slice, getDir)
}

// Other functions omitted

我有另一个文件 blocks.go,它的结构与 status.go 几乎相同,并且它不会导致此行为。我也不知道问题是由前面的类型 status 还是 cloudwind_block.go 文件中的某些内容引起的。

我使用 // 作为单行文档,使用 /* */ 作为多行文档。我尝试过偶尔使其保持一致,但正如预期的那样,它没有效果。


正确答案


分组和缩进的原因是这些函数被视为它们分组/缩进的类型的“构造函数”。

https://www.php.cn/link/31c49b512f199bc6f8734034a87dd9fa(如果您滚动往下一点,你会看到这个):

此示例还显示返回类型 T 或指针 *T 的顶级函数,可能会带有额外的错误结果,与类型 T 及其类型一起显示方法,假设它们是 T 的构造函数

卓越飞翔博客
上一篇: 如何从指令字节中获取相关的指令代码?
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏