doucheng1884 2018-08-01 20:17
浏览 167
已采纳

GoDoc添加换行符

I know that Golang supports documentation of functions via single-line comments starting with the name of the function (spelled "func"). However, there's a nauseating side effect: having multiple single line comments will not produce a GoDoc with newline characters separating each line of text

Here's a pic to illustrate:

enter image description here

Here's the func, and its documentation:

//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()
}

How does one insert newlines in the generated documentation? (If this were Javadoc, I would be like <br> and all would be good)

  • 写回答

1条回答 默认 最新

  • douji7399 2018-08-01 20:24
    关注

    Insert an empty comment line, and it will be a new paragraph, meaning it will start on a new line:

    // 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()
    }
    

    Recommended blog post: Godoc: documenting Go code

    Relevant section:

    There are a few formatting rules that Godoc uses when converting comments to HTML:

    • Subsequent lines of text are considered part of the same paragraph; you must leave a blank line to separate paragraphs.
    • Pre-formatted text must be indented relative to the surrounding comment text (see gob's doc.go for an example).
    • URLs will be converted to HTML links; no special markup is necessary.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))