嘗試godoc在一個簡單的平面代碼文件夾上提供服務。在線文檔沒有解釋如何實現這個簡單的任務。所以,創建這個簡單的結構,/tmp/testgodoc$ tree.└── src ├── main (just the binary) └── main.go1 directory, 2 filesmain.go 很簡單/tmp/testgodoc$ cat src/main.go// Hello godocpackage mainimport "fmt"// Say Hellofunc main() { fmt.Println("Hello")}在 GOPATH 或模塊模式下運行時,在瀏覽器中打開 localhost:6060 不會給出記錄當前文件夾的預期結果。在模塊模式下運行會給出以下輸出和結果:/tmp/testgodoc$ ~/go/bin/godoc -goroot=. -http=:6060using module mode; GOMOD=/dev/null(when Ctrl-C:) cannot find package "." in: /src/main^C并且在 GOPATH 模式下運行似乎指向本地標準庫:/tmp/testgodoc$ GO111MODULE=off ~/go/bin/godoc -goroot=. -http=:6060using GOPATH mode^C
1 回答

元芳怎么了
TA貢獻1798條經驗 獲得超7個贊
你應該把你的主包放到一個子目錄中,可能是這樣的:
~/go/src/testGoDoc$ tree
├── cmd
│ └── main.go
├── go.mod
└── pkg
└── test1
└── test_package.go
通過這個你可以運行這兩個命令:
godoc -http=:6060 #http://localhost:6060/pkg/<module name inside go.mod>/
和
GO111MODULE=off godoc -http=:6060 #http://localhost:6060/pkg/testGoDoc/
- 1 回答
- 0 關注
- 108 瀏覽
添加回答
舉報
0/150
提交
取消