我知道Golang通过单行注释支持函数的文档化,从函数的名称开始(拼写为"func")。然而,有一个令人作呕的副作用:拥有多个单行注释将不会产生带有换行符分隔每一行文本的GoDoc
这里有一张图片来说明:

这是函数,以及它的文档:
//GetFunctionName gets function name
// Parameters:
// - `i` : Function
// **NOTE** this func fails if `i` is a variable set to a func
// (they're called "anonymous functions" in JavaScript)
func GetFunctionName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}如何在生成的文档中插入换行符?(如果这是Javadoc,我会像<br>一样,一切都会很好)
发布于 2018-08-01 20:24:28
插入一个空的注释行,它将是一个新的段落,这意味着它将从一个新行开始:
// GetFunctionName gets function name
//
// Parameters:
// - `i` : Function
//
// **NOTE** this func fails if `i` is a variable set to a func
// (they're called "anonymous functions" in JavaScript)
func GetFunctionName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}推荐博客文章:Godoc:记录Go代码
相关章节:
在将注释转换为HTML时,Godoc使用了一些格式化规则:
https://stackoverflow.com/questions/51641640
复制相似问题