📈 GetStatistics
Fetches the overall statistics for the Packagist repository: total downloads, total packages, and total versions.
When to use
📊 Display the scale of the Packagist ecosystem on a dashboard; 🧭 evaluate the coverage of a self-hosted mirror relative to the official repository; 📅 periodically record the trend of these totals.
Signature
go
func (c *ComposerClient) GetStatistics() (*domain.StatisticsResponse, error)Parameters
This method takes no parameters.
Return value
| Value | Type | Description |
|---|---|---|
| Result | *domain.StatisticsResponse | Totals contains Downloads (int64), Packages, and Versions |
| Error | error | Returned on HTTP failure, non-200 status, or JSON parse failure |
Corresponding endpoint: GET https://packagist.org/statistics.json.
Example
go
package main
import (
"fmt"
"log"
"time"
"github.com/scagogogo/composer-skills/pkg/client"
)
func main() {
c := client.NewComposerClient(30 * time.Second)
stats, err := c.GetStatistics()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total downloads: %d\n", stats.Totals.Downloads)
fmt.Printf("Total packages: %d\n", stats.Totals.Packages)
fmt.Printf("Total versions: %d\n", stats.Totals.Versions)
}Advanced
- 📊 For per-package download statistics, use
GetPackageStats. - 📦 For the full set of package names, use
ListPackages. - 🔥 For a ranking of popular packages, use
ListPopularPackages.