Skip to content

Commit

Permalink
feature: download by proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Bpazy committed Aug 23, 2021
1 parent e32da03 commit 25d19ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ var downloadCmd = &cobra.Command{
func init() {
xrayCmd.AddCommand(downloadCmd)
rootCmd.AddCommand(xrayCmd)

downloadCmd.Flags().StringVarP(&xray.Cfg.GhProxy, "gh-proxy", "", "", "github proxy: https://github.com/hunshcn/gh-proxy")
}
10 changes: 10 additions & 0 deletions xray/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ type GithubLatestRelease struct {
Reactions *Reactions `json:"reactions"`
}

// DownloadConfig config for command: xraysub gen
type DownloadConfig struct {
GhProxy string // gh-proxy address
}

var Cfg = &DownloadConfig{}

func NewXrayDownloadCmdRun() func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
downloadUrl, fileName, err := getDownloadUrl()
Expand Down Expand Up @@ -158,6 +165,9 @@ func unzip(err error, fp string) error {

func download(err error, downloadUrl string, fileName string) (string, error) {
client := resty.New()
if Cfg.GhProxy != "" {
downloadUrl = Cfg.GhProxy + downloadUrl
}
res, err := client.R().SetDoNotParseResponse(true).Get(downloadUrl)
if err != nil {
return "", fmt.Errorf("download error: %w", err)
Expand Down

0 comments on commit 25d19ca

Please sign in to comment.