Skip to content

📈 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

ValueTypeDescription
Result*domain.StatisticsResponseTotals contains Downloads (int64), Packages, and Versions
ErrorerrorReturned 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

Released under the MIT License