Viewing Example functions with `go doc` command?

1k Views Asked by At

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?

3

There are 3 best solutions below

0
Cerise Limón On BEST ANSWER

It is not possible to display examples using the go doc command.

The command implementation ignores examples.

1
Mahdi zarepoor On

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

https://go.dev/blog/examples

1
Mitar On

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.