Open rhenwood-arm opened 6 years ago
Alternately, it may be that packages is meant to list only the paths, not any other metadata, and the ImportCount field in the corresponding struct is missing a `json:",omitempty"`
.
I've investigated this to try to find out the intention of the /packages
API endpoint. It's implemented here:
I've looked at the code of Database.AllPackages
method, and I can confirm it does not try to populate the import count nor any other fields aside from the package import path.
Other API endpoints do populate this field (as well as synopsis, etc.).
So it appears this is a bug in the sense that the /packages
endpoint JSON should not include the import_count
field. We need to take care when fixing it, because simply adding a omitempty
to ImportCount int `json:"import_count"`
would be problematic for other endpoints that do populate import counts. Having zero import count is a valid value and shouldn't be omitted for other endpoints.
I suspect the right fix would be to make a separate struct for JSON encoding packages for the /packages
endpoint, one that includes only Path
field.
Changing /packages
endpoint to include import counts would be a larger change, one that can't be done without evaluating whether the performance would be acceptable. /packages
already does a lot of work listing all known import paths.
Hi All,
Looking at the results of https://api.godoc.org/packages it seems that import_count is always 0. If this is confirmed, it seems this is not very useful and might be a bug. It would be much more useful to me to have the import_count values that are included in individual results (i.e. import_count: 326958, name: 'fmt' at time of writing).