mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
34 lines
2.2 KiB
Markdown
34 lines
2.2 KiB
Markdown
# 9.6 为你的自定义包使用godoc
|
||
godoc工具(3.6章节)在显示自定义包中的注释也有很好的效果:注释必须以//开始并无空行放在声明(包,类型,函数)前。godoc会为每个文件生成一系列的网页。
|
||
|
||
例如:
|
||
|
||
-在do_examples目录下我们有11.7章节中的用来排序的go文件,文件中有一些注释(文件需要未编译)
|
||
|
||
-命令行下进入目录下并输入命令:
|
||
|
||
godoc -http =:6060 -paht="."
|
||
|
||
(.是指当前目录,-path参数可以是/path/to/my/package1这样的形式指出package1在你源码中的位置或接受用冒号形式分隔的路径,无根目录的路径为相对于当前目录的相对路径)
|
||
|
||
-在浏览器打开地址 http://localhost:6060
|
||
|
||
然后你会看到本地的godoc页面(参见3.6章节)从左到右一次显示出目录中的包
|
||
doc_example:
|
||
|
||
doc_example | Packages | Commands | Specification
|
||
|
||
下面是链接到源码和所有对象时有序概述(所以是很好的浏览和查找源代码的方式),连同文件/评论。
|
||
|
||
sort包
|
||
|
||
func Float64sAreSorted
|
||
|
||
type IntArray
|
||
|
||
func IntsAreSortedfunc IsSortedfunc Sort
|
||
|
||
func (IntArray) Len
|
||
|
||
func SortFloat64s
|
||
|
||
func (IntArray) Less
|
||
|
||
func SortInts
|
||
|
||
func (IntArray) Swap
|
||
|
||
func SortStrings type Interface
|
||
|
||
func StringsAreSorted type StringArray
|
||
|
||
type Float64Array func (StringArray) Len
|
||
|
||
func (Float64Array) Len
|
||
|
||
func (StringArray) Less
|
||
|
||
func (Float64Array) Less
|
||
|
||
func (StringArray) Swap
|
||
|
||
func (Float64Array) Swap Other packages
|
||
|
||
import “doc_example”
|
||
使用通用的接口排序:
|
||
|
||
Package files
|
||
sort.go
|
||
func Float64sAreSorted[Top]
|
||
func Float64sAreSorted(a []float64) bool
|
||
func IntsAreSorted[Top]
|
||
func IntsAreSorted(a []int) bool
|
||
func IsSorted[Top]
|
||
func IsSorted(data Interface) bool
|
||
Test if data is sorted
|
||
func Sort[Top]
|
||
func Sort(data Interface)
|
||
General sort function
|
||
func SortInts[Top]
|
||
func SortInts(a []int)
|
||
Convenience wrappers for common cases
|
||
type IntArray[Top]
|
||
Convenience types for common cases: IntArray
|
||
type IntArray []int
|
||
|
||
如果你在一个团队中工作,并在源代码树被存储在网络硬盘上,就可以使用godoc给所有团队成员连续文档的支持。通过设置sync_minutes=n,你甚至可以让它自动更新您的文档每n分钟! |