-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/cmd/godoc: conditionally expose unexported types #7823
Comments
I assume you're talking about the web interface, in which case appending ?m=all to the URL should do what you want. There is no equivalent to this on the command-line interface (as noted by issue #8093). |
I thought I would provide an example of where this would be useful: type obj struct { RequiredProperty someType } func NewObj (p someType) *obj { return &obj { RequiredProperty p } } func (o *obj) ExportedMethod ( ) { // ... return ... } In this example, I want objects of type obj to only be created using the exported NewObj method. NewObj has exported properties and methods that (I feel) the documentation should show by default. |
#16043 got me thinking about this again, and I think I can better present my earlier thoughts: Exported v. unexported is an important distinction, but unexported elements can legally be part of the API of a package, directly or indirectly. I think there needs to be a notion of "accessible" elements in a package. This includes all exported elements as well as the subset of the unexported such that:
I've created a repo containing these cases: https://github.com/jimmyfrasche/inaccessible2godoc You can see these with ?m=all but you also see everything unexported that is not accessible by the above definition, which adds noise when all you wanted to know was the public API not the internals. I don't know if this concept needs to be in the language spec (unless it adds clarity, of course). But a general mechanism for computing the set of accessible items could be added to go/types or a package in x/. godoc could use that to filter instead of ast.IsExported to get the complete API for a package. There wouldn't need to be any special handling of fields and methods from embedded but unexported types, just a link to the unexported but accessible type as there would be were the type exported. golint likewise could chastise "unexported X is accessible and should be documented". I'm sure there are other uses. |
The text was updated successfully, but these errors were encountered: