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 的构造函数。