reg/registry/catalog.go
Jessica Tracy 32589e90be Passing context (#163)
* passing context in layer calls

* more contexting

* clair folder and context in handlers

* fixed token transport to reuse request context

* tests

* taking out context pass in server handlers
2018-12-29 12:09:10 -05:00

41 lines
807 B
Go

package registry
import (
"context"
"net/url"
"github.com/peterhellberg/link"
)
type catalogResponse struct {
Repositories []string `json:"repositories"`
}
// Catalog returns the repositories in a registry.
func (r *Registry) Catalog(ctx context.Context, u string) ([]string, error) {
if u == "" {
u = "/v2/_catalog"
}
uri := r.url(u)
r.Logf("registry.catalog url=%s", uri)
var response catalogResponse
h, err := r.getJSON(ctx, uri, &response)
if err != nil {
return nil, err
}
for _, l := range link.ParseHeader(h) {
if l.Rel == "next" {
unescaped, _ := url.QueryUnescape(l.URI)
repos, err := r.Catalog(ctx, unescaped)
if err != nil {
return nil, err
}
response.Repositories = append(response.Repositories, repos...)
}
}
return response.Repositories, nil
}