When to use Examples?

Hi all,

When do you use examples ? Do you combine them with godoc, can you share more details if you have been using them.

Personally I am experimenting with documenting code, and some examples appearing in godoc could be valuable, but am not sure if this is the standard.

Examples being included in the godoc is standard:

See also:

Next, take a look at this example:

And then take a look at the corresponding code:

https://cs.opensource.google/go/go/+/master:src/net/http/example_test.go;l=59?q=%2F%2F%20Simple%20static%20webserver:&ss=go%2Fgo:src%2Fnet%2Fhttp%2F

For me, examples are often all I need to get started with a module, and thus they are extremely useful. I can get a quick example and then discover the other surface area of the module Iā€™m using via intellisense / spelunking directly through the source. But I suppose it depends on the module.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.