英文:
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"标题:
type Level int
const (
Info Level = iota
Warning
Error
)
在godoc输出中,常量将显示在type Level
下方,位于文档的中间位置,而不是在顶部和包级别上方。
是否有办法在godoc中使用自定义类型,但仍将常量定义放在包级别上?
英文:
I find Godoc a great tool to automatically generate docs. But I found that, if I define a custom type and use it in my constant definition, in the godoc HTML, the constants will be displayed under that type, but not in the package level.
Here's a simple example:
const (
Info = iota
Warning
Error
)
This will generate a "Constants" heading at the top of the godoc. But if I do the following, there will be no Constants heading for the package
type Level int
const (
Info Level = iota
Warning
Error
)
In the godoc output, the constants will be displayed under type Level
, somewhere in the middle of the document, but not at the top and not in the package level.
Is there any way to use custom types, but still put the const definitions in the package level in godoc?
答案1
得分: 1
GoDoc按类型进行分组。无法将有类型的常量的文档移到包级别。对于“工厂”函数、方法等也是如此。
英文:
GoDoc groups by type. It is not possible to move the documentation for typed constants to the package level. The same applies to "factory" functions, methods, etc.
答案2
得分: 1
将其按以下方式编写将使const块显示在包级别。我不确定这是否是预期行为还是只是一种不一致性。
type Level int
const (
Info = Level(iota)
)
英文:
Writing it the following way will make the const block show up at package level. I’m not sure if this is intended behavior or just an inconsistency.
type Level int
const (
Info = Level(iota)
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论