fix(report): set http timeout 10 sec (#1154)
* fix(report): set http timeout 10 sec * fix: add an error handling
This commit is contained in:
17
util/util.go
17
util/util.go
@@ -3,6 +3,7 @@ package util
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
@@ -178,3 +179,19 @@ func Major(version string) string {
|
||||
}
|
||||
return ver[0:strings.Index(ver, ".")]
|
||||
}
|
||||
|
||||
// GetHttpClient return http.Client
|
||||
func GetHTTPClient(proxy string) (*http.Client, error) {
|
||||
if proxy != "" {
|
||||
proxyURL, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyURL(proxyURL),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return &http.Client{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user