8.2 使用godoc

在程序中我们一般都会注释,如果我们按照一定规则,godoc工具会收集这些注释并产生一个技术文档。

// Copyright 2009 The Go Authors. All rights reserved.  
// Use of this source code is governed by a BSD-style  
// license that can be found in the LICENSE file.   
package zlib
....
// A Writer takes data written to it and writes the compressed
// form of that data to an underlying writer (see NewWriter).
type Writer struct {
    w           io.Writer
    level       int
    dict        []byte
    compressor  * flate.Writer
    digest      hash.Hash32
    err         error
    scratch     [4]byte
    wroteHeader bool
}
// NewWriter creates a new Writer.
// Writes to the returned Writer are compressed and written to w.
//
// It is the caller's responsibility to call Close on the WriteCloser when done.
// Writes may be buffered and not flushed until Close.
func NewWriter(w io.Writer) * Writer {
    z, _ := NewWriterLevelDict(w, DefaultCompression, nil)
    return z
}

命令行下进入目录下并输入命令: godoc -http=:6060 -goroot="." 然后在浏览器打开地址:http://localhost:6060 然后你会看到本地的 Godoc 页面,从左到右一次显示出目录中的包。

下一节:在Go语言中,和编译有关的命令主要是go run ,go build , go install这三个命令。