Skip to content

Commit

Permalink
perf(vfox upgrade): upgrade vfox use http proxy (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-bar authored May 17, 2024
1 parent 1c2c463 commit 483b530
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cmd/commands/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"

"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/util"
)

Expand All @@ -39,8 +40,8 @@ var Upgrade = &cli.Command{
Action: upgradeCmd,
}

func fetchLatestVersion() (string, error) {
resp, err := http.Get("https://github.com/version-fox/vfox/tags")
func fetchLatestVersion(c *http.Client) (string, error) {
resp, err := c.Get("https://github.com/version-fox/vfox/tags")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -94,13 +95,13 @@ func generateUrls(currVersion string, tagName string) (string, string) {
return binURL, diffURL
}

func downloadFile(filepath string, url string) error {
func downloadFile(c *http.Client, filepath string, url string) error {
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
resp, err := http.Get(url)
resp, err := c.Get(url)
if err != nil {
return err
}
Expand All @@ -110,8 +111,12 @@ func downloadFile(filepath string, url string) error {
}

func upgradeCmd(ctx *cli.Context) error {
manager := internal.NewSdkManager()
defer manager.Close()
httpClient := manager.HttpClient()

currVersion := fmt.Sprintf("v%s", ctx.App.Version)
latestVersion, err := fetchLatestVersion()
latestVersion, err := fetchLatestVersion(httpClient)
if err != nil {
return cli.Exit("Failed to fetch the latest version: "+err.Error(), 1)
}
Expand Down Expand Up @@ -146,7 +151,7 @@ func upgradeCmd(ctx *cli.Context) error {

fmt.Println("Fetching", binURL)

if err := downloadFile(tempFile, binURL); err != nil {
if err := downloadFile(httpClient, tempFile, binURL); err != nil {
return cli.Exit("Failed to download file: "+err.Error(), 1)
}
decompressor := util.NewDecompressor(tempFile)
Expand Down

0 comments on commit 483b530

Please sign in to comment.