Skip to content

📦 GetPackage

Fetches the full information of a given package on Packagist, including versions, maintainers, download statistics, and GitHub metrics.

When to use

📦 When you need to display detailed metadata for a single package, such as a dependency dashboard or a package detail page; 🛠️ when building a self-hosted mirror and pulling the latest full snapshot; 📈 when monitoring a package's downloads and star count over time.

Signature

go
func (c *ComposerClient) GetPackage(packageName string) (*domain.ComposerPackageInfo, error)

Parameters

ParameterTypeDescription
packageNamestringPackage name in the form vendor/package, e.g. symfony/console

Return value

ValueTypeDescription
Result*domain.ComposerPackageInfoPackage info; the Package field holds the detailed metadata
ErrorerrorReturned on HTTP failure, non-200 status, or JSON parse failure

Corresponding endpoint: GET https://packagist.org/packages/{name}.json.

Example

go
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/scagogogo/composer-skills/pkg/client"
)

func main() {
	c := client.NewComposerClient(30 * time.Second)

	info, err := c.GetPackage("symfony/console")
	if err != nil {
		log.Fatalf("failed to get package info: %v", err)
	}
	fmt.Printf("Package name: %s\n", info.PackageName)
	fmt.Printf("Description: %s\n", info.Package.Description)
	fmt.Printf("Type: %s\n", info.Package.Type)
	fmt.Printf("GitHub stars: %d\n", info.Package.GithubStars)
	fmt.Printf("Total downloads: %d (monthly %d, daily %d)\n",
		info.Package.Downloads.Total,
		info.Package.Downloads.Monthly,
		info.Package.Downloads.Daily,
	)
	fmt.Printf("Version count: %d\n", len(info.Package.Versions))
}

Advanced

Response parsing

The endpoint returns a {"package": {...}} outer wrapper. The SDK first unmarshals into the wrapper to extract PackageInfo, then wraps it as ComposerPackageInfo and fills CreateTime / UpdateTime with the current time so you can persist it directly.

Released under the MIT License