@@ -31,14 +31,16 @@ type tags struct {
31
31
Tags []string `json:"tags"`
32
32
}
33
33
34
- // List wraps ListWithContext using the background context.
35
- func List (repo name.Repository , options ... Option ) ([]string , error ) {
36
- return ListWithContext (context .Background (), repo , options ... )
34
+ // ListWithContext calls List with the given context.
35
+ //
36
+ // Deprecated: Use List and WithContext. This will be removed in a future release.
37
+ func ListWithContext (ctx context.Context , repo name.Repository , options ... Option ) ([]string , error ) {
38
+ return List (repo , append (options , WithContext (ctx ))... )
37
39
}
38
40
39
- // ListWithContext calls /tags/list for the given repository, returning the list of tags
41
+ // List calls /tags/list for the given repository, returning the list of tags
40
42
// in the "tags" property.
41
- func ListWithContext ( ctx context. Context , repo name.Repository , options ... Option ) ([]string , error ) {
43
+ func List ( repo name.Repository , options ... Option ) ([]string , error ) {
42
44
o , err := makeOptions (repo , options ... )
43
45
if err != nil {
44
46
return nil , err
@@ -58,30 +60,22 @@ func ListWithContext(ctx context.Context, repo name.Repository, options ...Optio
58
60
RawQuery : "n=1000" ,
59
61
}
60
62
61
- // This is lazy, but I want to make sure List(..., WithContext(ctx)) works
62
- // without calling makeOptions() twice (which can have side effects).
63
- // This means ListWithContext(ctx, ..., WithContext(ctx2)) prefers ctx2.
64
- if o .context != context .Background () {
65
- ctx = o .context
66
- }
67
-
68
63
client := http.Client {Transport : tr }
69
64
tagList := []string {}
70
65
parsed := tags {}
71
66
72
67
// get responses until there is no next page
73
68
for {
74
69
select {
75
- case <- ctx .Done ():
76
- return nil , ctx .Err ()
70
+ case <- o . context .Done ():
71
+ return nil , o . context .Err ()
77
72
default :
78
73
}
79
74
80
- req , err := http .NewRequest ( "GET" , uri .String (), nil )
75
+ req , err := http .NewRequestWithContext ( o . context , "GET" , uri .String (), nil )
81
76
if err != nil {
82
77
return nil , err
83
78
}
84
- req = req .WithContext (ctx )
85
79
86
80
resp , err := client .Do (req )
87
81
if err != nil {
0 commit comments