简单的 godoc 你好世界

尝试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

http://img1.mukewang.com/6355ebc80001c39d04630248.jpg

并且在 GOPATH 模式下运行似乎指向本地标准库:


/tmp/testgodoc$ GO111MODULE=off ~/go/bin/godoc  -goroot=. -http=:6060

using GOPATH mode

^C

http://img3.mukewang.com/6355ebd700015f7904490801.jpg

红颜莎娜
浏览 90回答 1
1回答

元芳怎么了

你应该把你的主包放到一个子目录中,可能是这样的:~/go/src/testGoDoc$ tree├── cmd│&nbsp; &nbsp;└── main.go├── go.mod└── pkg&nbsp; &nbsp; └── test1&nbsp; &nbsp; &nbsp; &nbsp; └── 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/
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go