🧩 SearchPackagesByType
Searches packages on Packagist by keyword + package type, with pagination.
When to use
🧩 Search by keyword only within a specific type (e.g. composer-plugin); 🏗️ discover packages by combining type + functionality; 🎯 narrow the candidate set more precisely than a generic search.
Signature
go
func (c *ComposerClient) SearchPackagesByType(query, packageType string, perPage, page int) (*domain.SearchResponse, error)Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | Search keyword, e.g. installer |
packageType | string | Package type, e.g. composer-plugin, library |
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?q={query}&type={type}.
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.SearchPackagesByType("installer", "composer-plugin", 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 keyword only (without restricting type), use
SearchPackages. - 🏷️ To search by tags, use
SearchPackagesByTags. - 📋 To list all package names of a type (without a keyword), use
ListPackagesByType.