# 01.3.3 godoc

Go语言自带很多可以使你的程序员生活更加容易的工具。其中一个就是**godoc**，它可以帮助你在没有网络连接的情况下查看现存包和函数的文档。

**godoc**工具即可以像一般命令行命令那样直接在终端显示结果，也可以在命令行下启动一个web服务器。启动web服务器的，你需要一个浏览器来查看Go的文档。

第一种方式就像用man命令一样，不过我们查询的是Go的函数和包。因此，为了获取 fmt包中 Printf() 函数的信息，你可以执行下面的命令：



```
$ go doc fmt.Printf
```

同样的，你用下面这个命令可以找到**fmt**包的信息：

```
$ go doc fmt
`
```

第二种需要执行**godoc**命令，并且带&#x6709;**-http**参数：

```
$ godoc -http=:8001
```

上面命令中的数值，就是那个**8001**，是HTTP服务器监听的端口号。你可以使用任何你有权限，并且可用的值。然而，注意0到1023是被限制的，只有root用户可用，所以最好是避免使用这之间的一个，选个别的，并且这个端口没有被其他进程占用。

你也可以没有上面程序中那&#x4E2A;**=**，用一个空格代替。下面这个命令和上面的命令是完全一样的：

```
$ godoc -http :8001
```

然后，你就可以打开浏览器，访问<http://localhost:8001/pkg/>,就可以浏览Go的文档了。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hantmac.gitbook.io/mastering-go-second/01.0/01.3/01.3.3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
