Skip to content

Commit 8a1b239

Browse files
Use context while retrieving info manifest
1 parent 6bd6e7c commit 8a1b239

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

list.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package main
1717

1818
import (
19+
"context"
20+
1921
"github.com/jedib0t/go-pretty/v6/table"
2022
"github.com/spf13/cobra"
2123

@@ -31,16 +33,16 @@ func newListCmd() *cobra.Command {
3133
Short: "List the available Linux images",
3234
Args: cobra.NoArgs,
3335
Run: func(cmd *cobra.Command, args []string) {
34-
runListCommand()
36+
runListCommand(cmd.Context())
3537
},
3638
}
3739
return cmd
3840
}
3941

40-
func runListCommand() {
42+
func runListCommand(ctx context.Context) {
4143
client := updater.NewClient()
4244

43-
manifest, err := client.GetInfoManifest()
45+
manifest, err := client.GetInfoManifest(ctx)
4446
if err != nil {
4547
feedback.Fatal(i18n.Tr("error retrieving the manifest: %v", err), feedback.ErrBadArgument)
4648
}

updater/download_image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func DownloadImage(ctx context.Context, client *Client, targetVersion string, up
7373
var err error
7474

7575
feedback.Print(i18n.Tr("Checking for Debian image releases"))
76-
manifest, err := client.GetInfoManifest()
76+
manifest, err := client.GetInfoManifest(ctx)
7777
if err != nil {
7878
return nil, "", err
7979
}

updater/http_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ func (c *Client) addHeaders(req *http.Request) {
8080
}
8181

8282
// GetInfoManifest fetches and decodes the Debian images info.json.
83-
func (c *Client) GetInfoManifest() (Manifest, error) {
83+
func (c *Client) GetInfoManifest(ctx context.Context) (Manifest, error) {
8484
manifestURL := baseURL.JoinPath(pathRelease, "info.json").String()
85-
req, err := http.NewRequest("GET", manifestURL, nil)
85+
req, err := http.NewRequestWithContext(ctx, "GET", manifestURL, nil)
8686
if err != nil {
8787
return Manifest{}, fmt.Errorf("failed to create request: %w", err)
8888
}

0 commit comments

Comments
 (0)