Skip to content

Commit

Permalink
Support pagination for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Oct 19, 2022
1 parent efad427 commit e1260b1
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions registry/tags.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
package registry

import "context"
import (
"context"
"net/url"

"github.com/peterhellberg/link"
)

type tagsResponse struct {
Tags []string `json:"tags"`
}

// Tags returns the tags for a specific repository.
func (r *Registry) Tags(ctx context.Context, repository string) ([]string, error) {
url := r.url("/v2/%s/tags/list", repository)
r.Logf("registry.tags url=%s repository=%s", url, repository)
u := r.url("/v2/%s/tags/list", repository)
r.Logf("registry.tags url=%s repository=%s", u, repository)

var response tagsResponse
if _, err := r.getJSON(ctx, url, &response); err != nil {
h, err := r.getJSON(ctx, u, &response)
if err != nil {
return nil, err
}

for _, l := range link.ParseHeader(h) {
if l.Rel == "next" {
unescaped, _ := url.QueryUnescape(l.URI)
tags, err := r.Catalog(ctx, unescaped)
if err != nil {
return nil, err
}
response.Tags = append(response.Tags, tags...)
}
}

return response.Tags, nil
}

0 comments on commit e1260b1

Please sign in to comment.