golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.98k stars 17.67k forks source link

x/tools/cmd/godoc: option to show "exported" declarations of main packages #5727

Open lukescott opened 11 years ago

lukescott commented 11 years ago
What steps will reproduce the problem?
1. Run godoc -http=:8080
2. Go to http://localhost:8080/pkg/
3. Click on a package that is main

What is the expected output?

Documentation for exported components.

What do you see instead?

A blank page.

Which operating system are you using?

Mac OS X, Linux

Which version are you using?  (run 'go version')

Go1.1 (it worked in Go1.0)

Please provide any additional information below.

Our company uses Go as our primary language, and we have been successfully for a year
now. All we really want is a command-line option in godoc to export main like it used to
do in Go1.

This is for internal reasons. We use it to distinguish finalized verses experimental
functionality in our binaries, much like you would export something in a package to make
it available for use. This was extremely helpful in our company Hackathon - we would
communicate RPC calls to our iPhone developer without verbal communication. We got a lot
done. We've used this day to day, and it has helped a lot. Now we can't do this in Go
1.1.
robpike commented 11 years ago

Comment 1:

Labels changed: added priority-soon, godoc, removed priority-triage.

Owner changed to @griesemer.

robpike commented 11 years ago

Comment 2:

Status changed to Accepted.

griesemer commented 11 years ago

Comment 3:

A future version of godoc may be significantly refactored/rewritten and simplified,
which is why I'd rather not add an extra flag to godoc which then must be maintained.
But here's a very simple CL that does just that and illustrates how you can customize
godoc for your purposes. Let me know if this is what you are looking for; and if you can
live with your own custom version of godoc.
https://golang.org/cl/10409043

Status changed to WaitingForReply.

lukescott commented 11 years ago

Comment 4:

Will this future version have this option in some form? Because if that's the case, the
CL will hold us over until then. Otherwise I'd rather not have to maintain a custom
version of godoc forever.
As an idea for the future version: Instead of a flag could be show a hyperlink on the
cmd page that would allow you to view exported things anyway. There is an option to add
m=all to the URL manually to show private things in a package. Would be nice if both
things were linked on the page cmd/package pages.
adg commented 11 years ago

Comment 5:

I agree it would be a nice part of the UI. It would also be nice to have the option  to
see unexported declarations, too.

Labels changed: added priority-later, feature, removed priority-soon.

Status changed to Accepted.

rsc commented 10 years ago

Comment 6:

Labels changed: added go1.3maybe.

rsc commented 10 years ago

Comment 7:

Labels changed: removed feature.

rsc commented 10 years ago

Comment 8:

Labels changed: added release-none, removed go1.3maybe.

rsc commented 10 years ago

Comment 9:

Labels changed: added repo-tools.

griesemer commented 10 years ago

Comment 10:

Owner changed to bgarcia@golang.org.

gopherbot commented 10 years ago

Comment 11 by bt@brandonthomson.com:

Just had to rebuild my godoc for Go 1.3 and it's a bit more tricky to apply this change
now. First you need to get the go.tools repo because godoc has been moved into there.
Then, search for "info.IsMain = " in go.tools/godoc/server.go. Change that line to:
info.IsMain = false && pkgname == "main"
to change it permanently (or add a flag like the CL above if you really need it). Now to
build the binary you can cd into go.tools/cmd/godoc and do 'go install' or 'go build -o
godoc' or something like that.
Haven't tested it extensively yet but it seems to be working.
davecheney commented 10 years ago

Comment 12:

> to change it permanently (or add a flag like the CL above if you really need it). Now
to build the binary you can cd into go.tools/cmd/godoc and do 'go install' or 'go build
-o godoc' or something like that.
go install code.google.com/p/go.tools/cmd/godoc
will work from any location
drewwells commented 9 years ago

Instructions for the new location:

edit $GOPATH/src/golang.org/x/tools/godoc/server.go

- info.IsMain = pkgname == "main"
+ info.IsMain = false && pkgname == "main"

go install golang.org/x/tools/cmd/godoc
which -a godoc #make sure godoc built in $GOPATH/bin is the first one
mainali123 commented 9 months ago

Is there any 3rd party library to generate godoc for main package? I really need it.

drewwells commented 9 months ago

rename the package from main to somethingelse. Rename method main to Main. Create a main package that calls somethingelse.Main