Godoc with playground enabled

Hello!

This is about example functions and how they are presented in godoc.

Ideally I would like for my examples to show up in godoc with playground enabled,
so that I can run my examples directly within godoc.

I start my local godoc like this: godoc -http=:6060 -play

Still, the examples are shown, but w/o playground - just the source code.
but if I navigate to the stdlib eg to the strings package over there the examples get rendered nicely with playground.

What am I doing wrong here?

Any help appreciated!

Thanks
Horst

I am guessing that you need to move your examples into a test file that IS NOT in the same package as your package. Eg https://golang.org/src/strings/example_test.go is in the strings_test package.

Unfortunately, even after you do make those changes, the go playground won’t import third party packages from github etc (at least not to my knowledge) so you will end up with a sample that has the “run” button but doesn’t actually run.

1 Like

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