godoc with gopath
如果專案不用 go module,或是在專案外執行 godoc
那就是 gopath mode
godoc server 會從 gopath 去找src
godoc with go module
如果用go module,要確定module 模式是否正確
1. 專案目錄如果有 vendor 要刪掉
2. 在專案目錄 go env GOMOD
看是否有顯示 go.mod 的絕對路徑
3. 如果有,那就正確
4. 啟動 godoc -http=:6060
5. 瀏覽器 localhost:6060, 專案說明會在 pkg 下
Using wget to get godoc
1. Edit robots.txt in the go root dir, and remove "Disallow:/"
2. godoc -http=:6060
3. wget -r -np -E -p -k http://localhost:6060/pkg/pathToPackage
4. wget -m -k -q -erobots=off --no-host-directories --no-use-server-timestamps http://localhost:6060
-r : download recursive -np : don't ascend to the parent directory -N : don't retrieve files unless newer than local -E : add extension .html to html files (if they don't have) -p : download all necessary files for each page (css, js, images) -k : convert links to relative
注釋說明
詳細參考
http://c.biancheng.net/view/4035.html
package、const、variable、func 都支援註釋
只支援public (大寫開頭)的member 註釋輸出
註釋格式就是直接在member 上加上說明,
但是 func 的註釋要以 func名稱開頭
//PublicFunc
func PublicFunc(){
}
const(
//ConExample 是註釋範例
ConExample =10
)
var (
//VarExample是註釋範例
VarExample =10
)
const 內的 會顯示在 Constants 區段
var 內的 會顯示在 Variables 區段
建立範例 example
example_packageName_test.go
func exampleFuncName
func ExampleFuncName() {
logger.Info("hello, world.")
}
Bug 標示
這樣會顯示bug 標示
//BUG(rsc):
func BadFunc(){
}
沒有留言:
張貼留言