如果在 const 定义中声明和使用自定义类型,Godoc 不会生成 "const" 字段?
Godoc will not generate "const" field if custom type is declared and used in const definition?
我发现 Godoc 是自动生成文档的好工具。但是我发现,如果我定义一个自定义类型并在我的常量定义中使用它,在 godoc HTML 中,常量将显示在该类型下,而不是在包级别。
这是一个简单的例子:
const (
Info = iota
Warning
Error
)
这将在 godoc 的顶部生成一个 "Constants" 标题。但是如果我执行以下操作,将不会有 Constants heading for the package
type Level int
const (
Info Level = iota
Warning
Error
)
在 godoc 输出中,常量将显示在 type Level
下,在文档中间的某处,但不在顶部,也不在包级别。
有什么方法可以使用自定义类型,但仍然将 const 定义放在 godoc 的包级别?
GoDoc 按类型分组。无法将类型化常量的文档移动到包级别。 "factory" 函数、方法等也是如此
按以下方式编写将使 const 块显示在包级别。我不确定这是有意为之还是只是不一致。
type Level int
const (
Info = Level(iota)
)
我发现 Godoc 是自动生成文档的好工具。但是我发现,如果我定义一个自定义类型并在我的常量定义中使用它,在 godoc HTML 中,常量将显示在该类型下,而不是在包级别。
这是一个简单的例子:
const (
Info = iota
Warning
Error
)
这将在 godoc 的顶部生成一个 "Constants" 标题。但是如果我执行以下操作,将不会有 Constants heading for the package
type Level int
const (
Info Level = iota
Warning
Error
)
在 godoc 输出中,常量将显示在 type Level
下,在文档中间的某处,但不在顶部,也不在包级别。
有什么方法可以使用自定义类型,但仍然将 const 定义放在 godoc 的包级别?
GoDoc 按类型分组。无法将类型化常量的文档移动到包级别。 "factory" 函数、方法等也是如此
按以下方式编写将使 const 块显示在包级别。我不确定这是有意为之还是只是不一致。
type Level int
const (
Info = Level(iota)
)