Skip to content

🏷️ 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

ParameterTypeDescription
tags[]stringTag list, e.g. []string{"http", "psr-18"}; multiple tags are AND-combined
perPageintResults per page; pass 0 or negative to omit the per_page parameter
pageintPage number; pass 0 or negative to omit the page parameter

Return value

ValueTypeDescription
Result*domain.SearchResponseResults is []SearchResult, Total is the total count, Next is the URL of the next page
ErrorerrorReturned 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

Released under the MIT License