Update to go 1.19

This commit is contained in:
9seconds
2022-08-09 17:41:59 +03:00
parent 9d67414db6
commit f48156814b
60 changed files with 260 additions and 260 deletions
+6 -6
View File
@@ -12,8 +12,8 @@ import (
)
const (
addressesURLV4 = "https://core.telegram.org/getProxyConfig" // nolint: gas
addressesURLV6 = "https://core.telegram.org/getProxyConfigV6" // nolint: gas
addressesURLV4 = "https://core.telegram.org/getProxyConfig" //nolint: gas
addressesURLV6 = "https://core.telegram.org/getProxyConfigV6" //nolint: gas
)
var addressesProxyForSplitter = regexp.MustCompile(`\s+`)
@@ -74,12 +74,12 @@ func getAddresses(url string) (map[conntypes.DC][]string, conntypes.DC, error) {
}
func addressesParseProxyFor(text string) (string, conntypes.DC, error) {
chunks := addressesProxyForSplitter.Split(text, 3) // nolint: gomnd
chunks := addressesProxyForSplitter.Split(text, 3) //nolint: gomnd
if len(chunks) != 3 || chunks[0] != "proxy_for" {
return "", 0, fmt.Errorf("incorrect config %s", text)
}
dc, err := strconv.ParseInt(chunks[1], 10, 16) // nolint: gomnd
dc, err := strconv.ParseInt(chunks[1], 10, 16) //nolint: gomnd
if err != nil {
return "", 0, fmt.Errorf("incorrect config '%s': %w", text, err)
}
@@ -93,14 +93,14 @@ func addressesParseProxyFor(text string) (string, conntypes.DC, error) {
}
func addressesParseDefault(text string) (conntypes.DC, error) {
chunks := addressesProxyForSplitter.Split(text, 2) // nolint: gomnd
chunks := addressesProxyForSplitter.Split(text, 2) //nolint: gomnd
if len(chunks) != 2 || chunks[0] != "default" {
return 0, fmt.Errorf("incorrect config '%s'", text)
}
dcString := strings.TrimRight(chunks[1], ";")
dc, err := strconv.ParseInt(dcString, 10, 16) // nolint: gomnd
dc, err := strconv.ParseInt(dcString, 10, 16) //nolint: gomnd
if err != nil {
return 0, fmt.Errorf("incorrect config '%s': %w", text, err)
}
+3 -4
View File
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"
)
@@ -22,7 +21,7 @@ func request(url string) (io.ReadCloser, error) {
ctx, cancel := context.WithTimeout(context.Background(), apiHTTPTimeout)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
panic(err)
}
@@ -33,12 +32,12 @@ func request(url string) (io.ReadCloser, error) {
resp, err := httpClient.Do(req)
if err != nil {
if resp != nil {
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck
io.Copy(io.Discard, resp.Body) //nolint: errcheck
resp.Body.Close()
}
return nil, fmt.Errorf("cannot perform a request: %w", err)
}
return resp.Body, err // nolint: wrapcheck
return resp.Body, err //nolint: wrapcheck
}
+3 -3
View File
@@ -2,10 +2,10 @@ package api
import (
"fmt"
"io/ioutil"
"io"
)
const secretURL = "https://core.telegram.org/getProxySecret" // nolint: gas
const secretURL = "https://core.telegram.org/getProxySecret" //nolint: gas
func Secret() ([]byte, error) {
resp, err := request(secretURL)
@@ -15,7 +15,7 @@ func Secret() ([]byte, error) {
defer resp.Close()
secret, err := ioutil.ReadAll(resp)
secret, err := io.ReadAll(resp)
if err != nil {
return nil, fmt.Errorf("cannot read response: %w", err)
}
+2 -2
View File
@@ -51,7 +51,7 @@ func (b *baseTelegram) dial(dc conntypes.DC,
}
func (b *baseTelegram) getAddresses(dc conntypes.DC, protocol conntypes.ConnectionProtocol) []string {
addresses := make([]string, 0, 2) // nolint: gomnd
addresses := make([]string, 0, 2) //nolint: gomnd
protos := []conntypes.ConnectionProtocol{
conntypes.ConnectionProtocolIPv6,
conntypes.ConnectionProtocolIPv4,
@@ -86,7 +86,7 @@ func (b *baseTelegram) chooseAddress(addresses map[conntypes.DC][]string,
case len(addrs) == 1:
return addrs[0]
case len(addrs) > 1:
return addrs[rand.Intn(len(addrs))] // nolint: gosec
return addrs[rand.Intn(len(addrs))] //nolint: gosec
}
return ""