If I view a package's documentation via the web at https://pkg.go.dev, the page includes Example
test functions. The output of go doc -u -all
for a package does not. Is it possible to have such information included?
Asked
Active
Viewed 603 times
7

Colin Fraizer
- 532
- 4
- 14
-
1It is not possible to display examples using the `go doc` command. The command implementation ignores examples. – Charlie Tumahai Sep 10 '22 at 22:29
-
Thank you, @CeriseLimón. That seemed to be the case, but I was holding out hope. I don't mean to generate work for you, but would you consider turning your comment into an answer? – Colin Fraizer Sep 15 '22 at 03:48
3 Answers
3
It is not possible to display examples using the go doc
command.
The command implementation ignores examples.

Charlie Tumahai
- 113,709
- 12
- 249
- 242
1
Godoc examples are snippets of Go code that are displayed as package documentation and that are verified by running them as tests. They can also be run by a user visiting the godoc web page for the package and clicking the associated “Run” button

Mahdi zarepoor
- 310
- 1
- 6
-
1Thanks for the answer, but what I really wanted was just to see the examples in the terminal output—just like the rest of the go documentation, but I guess the `go doc` command does not allow this. – Colin Fraizer Aug 08 '23 at 01:06
0
I installed godoc with:
go install -v golang.org/x/tools/cmd/godoc@latest
And examples (if correctly named) are shown for me. I think you should correctly name your example functions in tests.

Mitar
- 6,756
- 5
- 54
- 86
-
Thanks for the answer. It's a good answer, but not what I wanted, which was just to see the examples in the terminal, not in my browser. – Colin Fraizer Aug 08 '23 at 01:04