1、 go doc
go doc go文件 查看go 文件的文档
2、在测试中加入 Example
package queue
// 定义别名
type Queue []interface{}
// push
func (q *Queue) Push(v interface{}) {
*q = append(*q, v)
}
// pop
func (q *Queue) Pop() interface{} {
head := (*q)[0]
*q = (*q)[1:]
return head
}
// is Empty
func (q *Queue) IsEmpty() bool {
return len(*q) == 0
}
package queue
import "fmt"
func ExampleQueue_Pop() {
q := Queue{1}
q.Push(2)
q.Push(3)
q.Push(3)
fmt.Println(q.Pop())
fmt.Println(q.Pop())
fmt.Println(q.IsEmpty())
fmt.Println(q.Pop())
fmt.Println(q.IsEmpty())
// Output:
//1
//2
//false
//3
//false
}
3、使用go doc 查看文件 ,使用godoc 生成文档
生成文件默认端口:6060
godoc在go 1.13里被拿掉了,我们需要另外安装。
安装的方法就是运行:(要确保第一章的国内镜像配置正确哦)
go get golang.org/x/tools/cmd/godoc
godoc可执行文件会被安装到的GOPATH下面的bin目录里,可以用go env GOPATH来查看当前的GOPATH