尝试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 关注
- 89 浏览
添加回答
举报
0/150
提交
取消