試圖godoc在一個簡單、扁平的代碼檔案夾上提供服務。在線檔案沒有解釋如何實作這個簡單的任務。
所以,創建這個簡單的結構,
/tmp/testgodoc$ tree
.
└── src
├── main (just the binary)
└── main.go
1 directory, 2 files
main.go 的位置很簡單
/tmp/testgodoc$ cat src/main.go
// Hello godoc
package main
import "fmt"
// Say Hello
func main() {
fmt.Println("Hello")
}
在 GOPATH 或模塊模式下運行時,在瀏覽器中打開 localhost:6060 不會給出記錄當前檔案夾的預期結果。
在模塊模式下運行給出以下輸出和結果:
/tmp/testgodoc$ ~/go/bin/godoc -goroot=. -http=:6060
using 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=:6060
using GOPATH mode
^C

uj5u.com熱心網友回復:
你應該把你的主包放在一個子目錄中,可能是這樣的:
~/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/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/400780.html
上一篇:使用密鑰加密訊息
