godoc的写法

一个不错的项目,可以用来学习godoc文档的写法

一些说明

  • 参考例子
func ExampleFoo()     // 作为Foo函数或者类型例子
func ExampleBar_Qux() // 作为Bar类型的Qux函数例子
func Example()        // 作为整个库的例子

通过这种规则,godoc将ExampleReverse函数对应到了Reverse这个函数

  • 扩展
func ExampleReverse()
func ExampleReverse_second()
func ExampleReverse_third()

通过增加 下划线+小写字母开头的单词作为后缀,一个函数可以对应多个例子

参考资料

https://blog.golang.org/examples
https://github.com/fluhus/godoc-tricks
https://pkg.go.dev/mod/github.com/fluhus/godoc-tricks
https://github.com/rongfengliang/golang-slug-learning
https://pkg.go.dev/github.com/rongfengliang/golang-slug-learning/v2@v2.0.6/pkg/id

posted on 2020-11-14 21:51  荣锋亮  阅读(249)  评论(0编辑  收藏  举报

导航