1

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?

4

2 回答 2

2

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.

于 2015-08-03T17:34:15.767 回答
1

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)
)
于 2017-09-16T14:44:57.940 回答