📦 ListPackagesWithData
Fetches the package name list along with the specified additional fields (such as repository URL, type, abandoned flag).
When to use
📦 Get the package name + repository URL in one call, avoiding an extra GetPackage per package; 🚮 identify abandoned packages for governance; 🧩 build a "package name → repository" mapping for mirroring or analysis.
Signature
go
func (c *ComposerClient) ListPackagesWithData(fields []string) (*domain.PackageListWithDataResponse, error)Parameters
| Parameter | Type | Description |
|---|---|---|
fields | []string | List of additional field names, e.g. []string{"repository", "type", "abandoned"} |
Return value
| Value | Type | Description |
|---|---|---|
| Result | *domain.PackageListWithDataResponse | Packages is a map[package name]PackageData containing the requested fields |
| Error | error | Returned on HTTP failure, non-200 status, or JSON parse failure |
Corresponding endpoint: GET https://packagist.org/packages/list.json?fields[]={f}&fields[]={f}.
Example
go
package main
import (
"fmt"
"log"
"time"
"github.com/scagogogo/composer-skills/pkg/client"
)
func main() {
c := client.NewComposerClient(30 * time.Second)
resp, err := c.ListPackagesWithData([]string{"repository", "type"})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Package count: %d\n", len(resp.Packages))
for name, data := range resp.Packages {
fmt.Printf(" %s -> %s (%s)\n", name, data.Repository, data.Type)
}
}Advanced
Available fields
Common available fields: repository (repository URL), type (package type), abandoned (abandoned flag, can be a bool or a replacement package name string).
- 📋 If you only need package names, use
ListPackages(smaller response). - 📊 If you need metrics such as downloads / stars, use
GetPackageorListPopularPackages.