godoc: example wont show up

477 views
Skip to first unread message

mhh...@gmail.com

unread,
Mar 6, 2017, 10:35:04 AM3/6/17
to golang-nuts
Hi,

in my package here, what did i do wrong so the ExampleMain won t show up ?

https://github.com/mh-cbon/emd

https://godoc.org/github.com/mh-cbon/emd

Im expecting to see
https://github.com/mh-cbon/emd/blob/master/main_test.go#L13

Note, go test works fine.

thanks!

Janne Snabb

unread,
Mar 6, 2017, 11:42:32 AM3/6/17
to golan...@googlegroups.com
Your example function is named ExampleMain(). This means that it is
supposed to document function Main() or type Main.

However, there is no function Main() or type Main in the package. Thus
the example is not visible in the documentation because there is nothing
for it to attach to.

See for example the following about the naming rules:

https://blog.golang.org/examples#TOC_4.


Janne Snabb
sn...@epipe.com
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

mhh...@gmail.com

unread,
Mar 6, 2017, 12:25:56 PM3/6/17
to golang-nuts

thanks for your reply.

yeah, that s right, ok, but what about TOC#5 ?

That should work too,

To achieve this we can use a "whole file example."
A whole file example is a file that ends in _test.go       
contains exactly one example function,                                        
no test or benchmark functions,                                                    
and at least one other package-level declaration.                         
When displaying such examples godoc will show the entire file.

: x

https://github.com/mh-cbon/emd/blob/master/main_test.go

Janne Snabb

unread,
Mar 6, 2017, 12:44:53 PM3/6/17
to golan...@googlegroups.com
It seems it is because it is "package main".

See $GOPATH/src/golang.org/x/tools/godoc/static/package.html template.

"IsMain" is set if the package is called "main". Looks like there is no
way to output examples in that case.


Janne Snabb
sn...@epipe.com

On 2017-03-06 19:25, mhh...@gmail.com wrote:
>
> thanks for your reply.
>
> yeah, that s right, ok, but what about TOC#5 ?
>
> That should work too,
>
> To achieve this we can use a "whole file example."
> A whole file example is a file that ends in |_test.go |✓
> contains exactly one example
> function, ✓
> no test or benchmark
> functions, ✓
> and at least one other package-level declaration. ✓
> When displaying such examples godoc will show the entire file.
>
> : x
>
> https://github.com/mh-cbon/emd/blob/master/main_test.go
>
>
> On Monday, March 6, 2017 at 5:42:32 PM UTC+1, Janne Snabb wrote:
>
> Your example function is named ExampleMain(). This means that it is
> supposed to document function Main() or type Main.
>
> However, there is no function Main() or type Main in the package. Thus
> the example is not visible in the documentation because there is
> nothing
> for it to attach to.
>
> See for example the following about the naming rules:
>
> https://blog.golang.org/examples#TOC_4
> <https://blog.golang.org/examples#TOC_4>.
>
>
> Janne Snabb
> sn...@epipe.com <javascript:>
>
> On 2017-03-06 17:35, mhh...@gmail.com <javascript:> wrote:
> > Hi,
> >
> > in my package here, what did i do wrong so the ExampleMain won t
> show up ?
> >
> > https://github.com/mh-cbon/emd
> >
> > https://godoc.org/github.com/mh-cbon/emd
> <https://godoc.org/github.com/mh-cbon/emd>
> >
> > Im expecting to see
> > https://github.com/mh-cbon/emd/blob/master/main_test.go#L13
> <https://github.com/mh-cbon/emd/blob/master/main_test.go#L13>
> >
> > Note, go test works fine.
> >
> > thanks!
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "golang-nuts" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to golang-nuts...@googlegroups.com <javascript:>
> > <mailto:golang-nuts...@googlegroups.com <javascript:>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages