1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-22 13:19:02 +08:00

fix: common download save to file

Signed-off-by: zu1k <i@zu1k.com>
This commit is contained in:
zu1k 2022-07-04 22:01:03 +08:00
parent 5b691874f4
commit 2f1d16408c
4 changed files with 13 additions and 10 deletions

4
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/ip2location/ip2location-go/v9 v9.4.0 github.com/ip2location/ip2location-go/v9 v9.4.0
github.com/ipipdotnet/ipdb-go v1.3.1 github.com/ipipdotnet/ipdb-go v1.3.1
github.com/lionsoul2014/ip2region v2.2.0-release+incompatible github.com/lionsoul2014/ip2region v2.2.0-release+incompatible
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220624075035-53e6777abd9d github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220704023600-9376c56688c8
github.com/oschwald/geoip2-golang v1.7.0 github.com/oschwald/geoip2-golang v1.7.0
github.com/saracen/go7z v0.0.0-20191010121135-9c09b6bd7fda github.com/saracen/go7z v0.0.0-20191010121135-9c09b6bd7fda
github.com/spf13/cobra v1.5.0 github.com/spf13/cobra v1.5.0
@ -35,7 +35,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.0 // indirect github.com/subosito/gotenv v1.4.0 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect github.com/ulikunitz/xz v0.5.10 // indirect
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b // indirect golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect
golang.org/x/tools v0.1.7 // indirect golang.org/x/tools v0.1.7 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect

4
go.sum
View File

@ -146,6 +146,8 @@ github.com/lionsoul2014/ip2region v2.2.0-release+incompatible h1:1qp9iks+69h7IGL
github.com/lionsoul2014/ip2region v2.2.0-release+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI= github.com/lionsoul2014/ip2region v2.2.0-release+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI=
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220624075035-53e6777abd9d h1:E9eY3SL8JWS+mJds+Uk0OGAbLMLvMvEiebAGmo2fp1U= github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220624075035-53e6777abd9d h1:E9eY3SL8JWS+mJds+Uk0OGAbLMLvMvEiebAGmo2fp1U=
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220624075035-53e6777abd9d/go.mod h1:bChUKvbKVC3zL/lLLIcu6alhQaL8uWD/DA+jRdyggdI= github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220624075035-53e6777abd9d/go.mod h1:bChUKvbKVC3zL/lLLIcu6alhQaL8uWD/DA+jRdyggdI=
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220704023600-9376c56688c8 h1:aHOC8Mcbd3TiCb+L9cSbU/NdZinWuaKSoL4qD4I3MQo=
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20220704023600-9376c56688c8/go.mod h1:bChUKvbKVC3zL/lLLIcu6alhQaL8uWD/DA+jRdyggdI=
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
@ -344,6 +346,8 @@ golang.org/x/sys v0.0.0-20220624220833-87e55d714810 h1:rHZQSjJdAI4Xf5Qzeh2bBc5YJ
golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b h1:2n253B2r0pYSmEV+UNCQoPfU/FiaizQEK5Gu4Bq4JE8= golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b h1:2n253B2r0pYSmEV+UNCQoPfU/FiaizQEK5Gu4Bq4JE8=
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e h1:CsOuNlbOuf0mzxJIefr6Q4uAUetRUwZE4qt7VfzP+xo=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -2,6 +2,7 @@ package common
import ( import (
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"time" "time"
) )
@ -16,11 +17,11 @@ var httpClient *HttpClient
func init() { func init() {
httpClient = &HttpClient{http.DefaultClient} httpClient = &HttpClient{http.DefaultClient}
httpClient.Timeout = time.Second * 30 httpClient.Timeout = time.Second * 60
httpClient.Transport = &http.Transport{ httpClient.Transport = &http.Transport{
TLSHandshakeTimeout: time.Second * 5, TLSHandshakeTimeout: time.Second * 5,
IdleConnTimeout: time.Second * 20, IdleConnTimeout: time.Second * 10,
ResponseHeaderTimeout: time.Second * 20, ResponseHeaderTimeout: time.Second * 10,
ExpectContinueTimeout: time.Second * 20, ExpectContinueTimeout: time.Second * 20,
} }
} }
@ -37,9 +38,9 @@ func (c *HttpClient) Get(urls ...string) (body []byte, err error) {
for _, url := range urls { for _, url := range urls {
req, err = http.NewRequest(http.MethodGet, url, nil) req, err = http.NewRequest(http.MethodGet, url, nil)
if err != nil { if err != nil {
log.Println(err)
continue continue
} }
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.Header.Set("User-Agent", UserAgent) req.Header.Set("User-Agent", UserAgent)
resp, err = c.Do(req) resp, err = c.Do(req)

View File

@ -16,10 +16,8 @@ func Download(filePath string, urls ...string) (data []byte, err error) {
return return
} }
if len(filePath) == 1 { if err := common.SaveFile(filePath, data); err == nil {
if err := common.SaveFile(filePath, data); err == nil { log.Println("文件下载成功:", filePath)
log.Println("文件下载成功:", filePath)
}
} }
return return
} }