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?
Viewing Example functions with `go doc` command?
It is not possible to display examples using the go doc
command.
The command implementation ignores examples.
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
Thanks 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. –
Karalee 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.
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. –
Karalee
© 2022 - 2024 — McMap. All rights reserved.
go doc
command. The command implementation ignores examples. – Oasis