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

feat: add default user-agent string #57

Merged
merged 2 commits into from
Oct 20, 2022
Merged

feat: add default user-agent string #57

merged 2 commits into from
Oct 20, 2022

Conversation

septs
Copy link
Contributor

@septs septs commented Oct 18, 2022

user-agent string like Wget

$ pget https://mirrors.tuna.tsinghua.edu.cn/archlinux/iso/latest/archlinux-2022.10.01-x86_64.iso
2.40 KiB / 798.32 MiB [>____________________________________________________________________________________________] 0.00% 1.75 MiB p/s

binding with files...
2.40 KiB / 798.32 MiB [>___________________________________________________________________________________________________] 0.00% ? p/s
$ cat archlinux-2022.10.01-x86_64.iso
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>清华大学 TUNA 镜像站</title>
    <link href="//cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <style> body { padding-top: 40px; } </style>
  </head>
  <body>
    <div class="container">
      <div class="well">
        <p lang="zh-cn">尊敬的访问者,</p>
		<p lang="en">Dear visitor, </p>
		<p lang="fr">Chère cliente, </p>
		<p lang="ja">訪問者へ 、</p>
		<p>&nbsp;</p>
        <p lang="zh-cn">您好!</p>
		<p lang="en">Hello! </p>
		<p lang="fr">Bonjour! </p>
		<p lang="ja">こんにちは !</p>
		<p>&nbsp;</p>
        <p lang="zh-cn">我们检测到您正在使用移动设备下载镜像站上较大的二进制文件,为防止消耗过多流量,我们建议您改用计算机下载。</p>
		<p lang="en">Your attempt to download a large binary file from a mobile device has been detected. To avoid excessive consumption of data transfer, you are recommended to download it from a computer. </p>
		<p lang="fr">Une tentative de téléchargement d'un fichier binaire de grande taille depuis un appareil mobile a été détectée. Afin d'éviter une consommation excessive de données mobile, nous vous conseillons de recommencer cette action à partir d'un ordinateur. </p>
		<p lang="ja">容量の大きいバイナリファイルが今モバイルデバイスに転送しようとしております、大量のトラフィックが発生するため、コンピュータからのダウンロードをお勧めします。</p>
		<p>&nbsp;</p>
		<p lang="zh-cn">如有疑问,请联系 <a href="mailto:support@tuna.tsinghua.edu.cn">support@tuna.tsinghua.edu.cn</a> 。</p>
		<p lang="en">If there are any possible questions, please contact <a href="mailto:support@tuna.tsinghua.edu.cn">support@tuna.tsinghua.edu.cn</a>. </p>
		<p lang="fr">Pour plus d'informations, veuillez contacter <a href="mailto:support@tuna.tsinghua.edu.cn">support@tuna.tsinghua.edu.cn</a>. </p>
		<p lang="ja">なおご質問などありましたら、<a href="mailto:support@tuna.tsinghua.edu.cn">support@tuna.tsinghua.edu.cn</a>までご連絡してください。</p>
		<p>&nbsp;</p>
                <p><code>00000070 37eec832d885647d98c2056b54651fd4</code></p>
      </div>
    </div>
  </body>
</html>
$ pget --user-agent 'Pget/0.1.1' https://mirrors.tuna.tsinghua.edu.cn/archlinux/iso/latest/archlinux-2022.10.01-x86_64.iso
1.04 MiB / 798.32 MiB [>__________________________________________________________________________________________] 0.13% 894.55 KiB p/s^C

@codecov
Copy link

codecov bot commented Oct 19, 2022

Codecov Report

Merging #57 (54dd6ed) into master (7c82871) will increase coverage by 0.71%.
The diff coverage is 100.00%.

❗ Current head 54dd6ed differs from pull request most recent head 12ae3ab. Consider uploading reports for the commit 12ae3ab to get more accurate results

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
+ Coverage   69.56%   70.27%   +0.71%     
==========================================
  Files           7        7              
  Lines         506      508       +2     
==========================================
+ Hits          352      357       +5     
+ Misses        114      112       -2     
+ Partials       40       39       -1     
Impacted Files Coverage Δ
download.go 73.62% <100.00%> (+1.95%) ⬆️
pget.go 55.55% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

download.go Outdated Show resolved Hide resolved
@septs septs requested a review from Code-Hex October 19, 2022 14:47
@@ -131,8 +129,11 @@ type DownloadConfig struct {

type DownloadOption func(c *DownloadConfig)

func WithUserAgent(ua string) DownloadOption {
func WithUserAgent(ua, version string) DownloadOption {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version parameter is unnecessary. Because version is global variable. Could you remove this one?

Suggested change
func WithUserAgent(ua, version string) DownloadOption {
func WithUserAgent(ua string) DownloadOption {

Copy link
Contributor Author

@septs septs Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ldflags: -s -w -X main.version={{.Version}}

var version string

if err := cli.Run(context.Background(), version, os.Args[1:]); err != nil {

pget/pget.go

Lines 41 to 44 in 7c82871

func (pget *Pget) Run(ctx context.Context, version string, args []string) error {
if err := pget.Ready(version, args); err != nil {
return errTop(err)
}

The version not is global variable, only main file exists

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I forget my code

@septs septs requested a review from Code-Hex October 20, 2022 01:10
Copy link
Owner

@Code-Hex Code-Hex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Code-Hex Code-Hex merged commit 8f357a2 into Code-Hex:master Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants