🏷️ SearchPackagesByTags
Searches packages on Packagist by tags, supporting multiple tags and pagination.
When to use
🏷️ Discover packages in the same domain by functional tags (e.g. http, psr-18); 🧩 build a "browse by tag" directory page; 🎯 combine multiple tags for precise filtering.
Signature
go
func (c *ComposerClient) SearchPackagesByTags(tags []string, perPage, page int) (*domain.SearchResponse, error)Parameters
| Parameter | Type | Description |
|---|---|---|
tags | []string | Tag list, e.g. []string{"http", "psr-18"}; multiple tags are AND-combined |
perPage | int | Results per page; pass 0 or negative to omit the per_page parameter |
page | int | Page number; pass 0 or negative to omit the page parameter |
Return value
| Value | Type | Description |
|---|---|---|
| Result | *domain.SearchResponse | Results is []SearchResult, Total is the total count, Next is the URL of the next page |
| Error | error | Returned on HTTP failure, non-200 status, or JSON parse failure |
Corresponding endpoint: GET https://packagist.org/search.json?tags={t}&tags={t}. Each tag is passed as a separate tags query parameter.
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.SearchPackagesByTags([]string{"http", "client"}, 15, 1)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total results: %d\n", resp.Total)
for i, r := range resp.Results {
fmt.Printf("%2d. %s — %s\n", i+1, r.Name, r.Description)
}
}Advanced
- 🔍 To search by free-form keywords, use
SearchPackages. - 🧩 To search by type + keyword, use
SearchPackagesByType. - 📦 Once you have a package name, fetch the full details with
GetPackage.