|
1 | 1 | package registry
|
2 | 2 |
|
3 |
| -import "context" |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/url" |
| 6 | + |
| 7 | + "github.com/peterhellberg/link" |
| 8 | +) |
4 | 9 |
|
5 | 10 | type tagsResponse struct {
|
6 | 11 | Tags []string `json:"tags"`
|
7 | 12 | }
|
8 | 13 |
|
9 | 14 | // Tags returns the tags for a specific repository.
|
10 | 15 | 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) |
13 | 18 |
|
14 | 19 | 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 { |
16 | 22 | return nil, err
|
17 | 23 | }
|
| 24 | + tags := response.Tags |
| 25 | + |
| 26 | + for _, l := range link.ParseHeader(h) { |
| 27 | + if l.Rel == "next" { |
| 28 | + unescaped, _ := url.QueryUnescape(l.URI) |
| 29 | + h, err = r.getJSON(ctx, unescaped, &response) |
| 30 | + if err != nil { |
| 31 | + return nil, err |
| 32 | + } |
| 33 | + tags = append(tags, response.Tags...) |
| 34 | + } |
| 35 | + } |
18 | 36 |
|
19 |
| - return response.Tags, nil |
| 37 | + return tags, nil |
20 | 38 | }
|
0 commit comments