Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(vfox upgrade): upgrade vfox use http proxy #274

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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