没有不值得去解决的问题,也没有不值得去学习的技术!

How to Deploy a Local Go 1.13 Documentation Web Server on Windows 10 Without godoc.exe

Opening http://localhost:6060 in a browser. It loads normally, as expected.

1. The go doc tool can only retrieve comment content from the ../go/src directory under the Go installation directory. In addition, it can serve as a local documentation browsing web server. Enter godoc -http=:6060 in the command line, then open http://localhost:6060 in a browser, and you will see the page provided by the local documentation browsing server. Reference URL: https://github.com/unknwon/the-way-to-go_ZH_CN/blob/master/eBook/03.6.md

2. Running godoc -http=:6060 in the command line returns an error: “godoc” is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. See Figure 1.

Running godoc -http=:6060 in the command line returns an error: "godoc" is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Figure 1
Plaintext
PS C:\Go> godoc -http=:6060
godoc : 无法将“godoc”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正
确,然后再试一次。
所在位置 行:1 字符: 1
+ godoc -http=:6060
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (godoc:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


3. I navigated to the C:\Go\bin directory to check the files and found that godoc.exe does not exist.

Plaintext
PS C:\Go> cd bin
PS C:\Go\bin> ls


    目录: C:\Go\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2019/10/31     22:59       14797824 go.exe
-a----       2019/10/31     22:59        3715072 gofmt.exe



4. I checked the Go version by running the command: go version. Reference URL: https://golang.org/doc/go1.13#godoc . The Godoc web server is no longer included in the main binary distribution. To run the godoc web server locally, you need to install it manually first.

Plaintext

PS C:\Go> go version
go version go1.13.4 windows/amd64

5. go install compiles and installs its own packages and dependencies. I ran go install golang.org/x/tools/cmd/godoc (https://github.com/golang/tools/tree/master/godoc). Reference URL: https://www.shuijingwanwq.com/2019/12/28/3784/ to resolve the error.

Plaintext

PS C:\Go> go install golang.org/x/tools/cmd/godoc
C:\Users\Administrator\go\src\golang.org\x\tools\cmd\godoc\main.go:47:2: cannot find package "golang.org/x/xerrors" in a
ny of:
        c:\go\src\golang.org\x\xerrors (from $GOROOT)
        C:\Users\Administrator\go\src\golang.org\x\xerrors (from $GOPATH)
PS C:\Go> set HTTP_PROXY=http://127.0.0.1:50999
PS C:\Go> set HTTPS_PROXY=http://127.0.0.1:50999
PS C:\Go> go install golang.org/x/tools/cmd/godoc
go: downloading golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
go: extracting golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898

6. I ran godoc -http=:6060 in the command line again, and it succeeded.

Plaintext

PS C:\Go> godoc -http=:6060
using GOPATH mode


7. I opened http://localhost:6060 in a browser. It loaded normally, as expected. See Figure 2.

Opening http://localhost:6060 in a browser. It loads normally, as expected.
Figure 2

8. I navigated to the C:\Go\bin directory to check the files and found that godoc.exe still does not exist. I then navigated to the C:\Users\Administrator\go\bin directory to check the files and found that godoc.exe already exists, as expected. See Figure 3.

Navigating to the C:\Go\bin directory to check the files, godoc.exe still does not exist. Navigating to the C:\Users\Administrator\go\bin directory to check the files, godoc.exe already exists, as expected.
Figure 3
Plaintext
PS C:\Go> cd C:\Go\bin
PS C:\Go\bin> ls


    目录: C:\Go\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2019/10/31     22:59       14797824 go.exe
-a----       2019/10/31     22:59        3715072 gofmt.exe


PS C:\Go\bin> cd C:\Users\Administrator\go\bin
PS C:\Users\Administrator\go\bin> ls


    目录: C:\Users\Administrator\go\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2020/02/20     18:17       16660480 godoc.exe
-a----       2020/02/20     18:34       14633984 tour.exe



关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系