Skip to content

Commit e1260b1

Browse files
Support pagination for tags
1 parent efad427 commit e1260b1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

registry/tags.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
package registry
22

3-
import "context"
3+
import (
4+
"context"
5+
"net/url"
6+
7+
"github.com/peterhellberg/link"
8+
)
49

510
type tagsResponse struct {
611
Tags []string `json:"tags"`
712
}
813

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

1419
var response tagsResponse
15-
if _, err := r.getJSON(ctx, url, &response); err != nil {
20+
h, err := r.getJSON(ctx, u, &response)
21+
if err != nil {
1622
return nil, err
1723
}
1824

25+
for _, l := range link.ParseHeader(h) {
26+
if l.Rel == "next" {
27+
unescaped, _ := url.QueryUnescape(l.URI)
28+
tags, err := r.Catalog(ctx, unescaped)
29+
if err != nil {
30+
return nil, err
31+
}
32+
response.Tags = append(response.Tags, tags...)
33+
}
34+
}
35+
1936
return response.Tags, nil
2037
}

0 commit comments

Comments
 (0)