🧩 GetPackageWithV2Metadata
Fetches package info in Composer V2 metadata format (raw JSON bytes), including the full version tree.
When to use
🧩 When building a self-hosted Composer repository or mirror that must serve the p2 metadata required by the V2 resolver; ⚙️ when you need the precise version array per version (including dist/source) for version constraint resolution.
Signature
func (c *ComposerClient) GetPackageWithV2Metadata(packageName string) ([]byte, error)Parameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | Package name, e.g. symfony/console |
Return value
| Value | Type | Description |
|---|---|---|
| Data | []byte | Raw JSON bytes of the V2 metadata |
| Error | error | Returned on HTTP failure or non-200 status |
Corresponding endpoint: GET https://repo.packagist.org/p2/{name}.json (uses repoURL, default https://repo.packagist.org).
Example
package main
import (
"fmt"
"log"
"time"
"github.com/scagogogo/composer-skills/pkg/client"
)
func main() {
c := client.NewComposerClient(30 * time.Second)
data, err := c.GetPackageWithV2Metadata("symfony/console")
if err != nil {
log.Fatal(err)
}
// Parse according to the V2 schema yourself, or write it straight to disk
fmt.Println(string(data))
}Advanced
Why does it return []byte?
The V2 metadata structure is complex (with multi-level nesting of packages.{name}.{version} and minified fields), and different consumers care about different fields. Therefore the SDK does not force a model on it — it returns the raw JSON so the caller can parse it as needed.
- 🌐 For self-hosted mirrors, use
WithRepoURLto point at a private V2 repository. - 🧪 To fetch development branch versions, use
GetPackageDevVersions. - 📦 For structured package info (including download statistics), use
GetPackage.