我想在函数的注释中包括一些示例代码,如下所示:

// Some example for using `foo`:
//
// ```
//   f := Foo(...)
//   g := Goo(f)
// ```
func Foo() {
  ...
}

但是代码块在vscode中无法正确显示。正确的做法是什么?

最佳答案

删除那些反引号,然后缩进代码:

// Foo does ... (note this first line)
// Some example for using Foo:
//
//   f := Foo(...)
//   g := Goo(f)
func Foo() {
  ...
}
The Go Blog: Godoc: documenting Go code:报价

相关问题:
Godoc documentation not outputting lists
GoDoc add newline character
What are Go example functions?

关于go - 在go函数注释中编写代码块的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64314605/

10-16 23:53