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
+37 -37
View File
@@ -79,29 +79,29 @@ const (
type Config struct {
Bind *net.TCPAddr `json:"bind"`
PublicIPv4 *net.TCPAddr `json:"public_ipv4"` // nolint: tagliatelle
PublicIPv6 *net.TCPAddr `json:"public_ipv6"` // nolint: tagliatelle
StatsBind *net.TCPAddr `json:"stats_bind"` // nolint: tagliatelle
StatsdAddr *net.TCPAddr `json:"stats_addr"` // nolint: tagliatelle
StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"` // nolint: tagliatelle
PublicIPv4 *net.TCPAddr `json:"public_ipv4"` //nolint: tagliatelle
PublicIPv6 *net.TCPAddr `json:"public_ipv6"` //nolint: tagliatelle
StatsBind *net.TCPAddr `json:"stats_bind"` //nolint: tagliatelle
StatsdAddr *net.TCPAddr `json:"stats_addr"` //nolint: tagliatelle
StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"` //nolint: tagliatelle
StatsNamespace string `json:"stats_namespace"` // nolint: tagliatelle
CloakHost string `json:"cloak_host"` // nolint: tagliatelle
StatsdTags map[string]string `json:"statsd_tags"` // nolint: tagliatelle
StatsNamespace string `json:"stats_namespace"` //nolint: tagliatelle
CloakHost string `json:"cloak_host"` //nolint: tagliatelle
StatsdTags map[string]string `json:"statsd_tags"` //nolint: tagliatelle
WriteBuffer int `json:"write_buffer"` // nolint: tagliatelle
ReadBuffer int `json:"read_buffer"` // nolint: tagliatelle
CloakPort int `json:"cloak_port"` // nolint: tagliatelle
WriteBuffer int `json:"write_buffer"` //nolint: tagliatelle
ReadBuffer int `json:"read_buffer"` //nolint: tagliatelle
CloakPort int `json:"cloak_port"` //nolint: tagliatelle
AntiReplayMaxSize int `json:"anti_replay_max_size"` // nolint: tagliatelle
AntiReplayMaxSize int `json:"anti_replay_max_size"` //nolint: tagliatelle
MultiplexPerConnection int `json:"multiplex_per_connection"` // nolint: tagliatelle
MultiplexPerConnection int `json:"multiplex_per_connection"` //nolint: tagliatelle
Debug bool `json:"debug"`
Verbose bool `json:"verbose"`
SecretMode SecretMode `json:"secret_mode"` // nolint: tagliatelle
PreferIP PreferIP `json:"prefer_ip"` // nolint: tagliatelle
NTPServers []string `json:"ntp_servers"` // nolint: tagliatelle
SecretMode SecretMode `json:"secret_mode"` //nolint: tagliatelle
PreferIP PreferIP `json:"prefer_ip"` //nolint: tagliatelle
NTPServers []string `json:"ntp_servers"` //nolint: tagliatelle
Secret []byte `json:"secret"`
AdTag []byte `json:"adtag"`
@@ -146,7 +146,7 @@ func (c *Config) adjustProxyValue(value int) int {
fvalue := float64(value)
newValue := fvalue * 2 * math.Log(float64(c.MultiplexPerConnection)) // nolint: gomnd
newValue := fvalue * 2 * math.Log(float64(c.MultiplexPerConnection)) //nolint: gomnd
newValue = math.Ceil(newValue)
newValue = math.Max(fvalue, newValue)
@@ -160,15 +160,15 @@ type Opt struct {
var C = Config{}
func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
func Init(options ...Opt) error { //nolint: gocyclo, funlen, cyclop
for _, opt := range options {
switch opt.Option {
case OptionTypeDebug:
C.Debug = opt.Value.(bool) // nolint: forcetypeassert
C.Debug = opt.Value.(bool) //nolint: forcetypeassert
case OptionTypeVerbose:
C.Verbose = opt.Value.(bool) // nolint: forcetypeassert
C.Verbose = opt.Value.(bool) //nolint: forcetypeassert
case OptionTypePreferIP:
value := opt.Value.(string) // nolint: forcetypeassert
value := opt.Value.(string) //nolint: forcetypeassert
switch value {
case "ipv4":
C.PreferIP = PreferIPv4
@@ -178,25 +178,25 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
return fmt.Errorf("incorrect direct IP mode %s", value)
}
case OptionTypeBind:
C.Bind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
C.Bind = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
case OptionTypePublicIPv4:
C.PublicIPv4 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
C.PublicIPv4 = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
if C.PublicIPv4 == nil {
C.PublicIPv4 = &net.TCPAddr{}
}
case OptionTypePublicIPv6:
C.PublicIPv6 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
C.PublicIPv6 = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
if C.PublicIPv6 == nil {
C.PublicIPv6 = &net.TCPAddr{}
}
case OptionTypeStatsBind:
C.StatsBind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
C.StatsBind = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
case OptionTypeStatsNamespace:
C.StatsNamespace = opt.Value.(string) // nolint: forcetypeassert
C.StatsNamespace = opt.Value.(string) //nolint: forcetypeassert
case OptionTypeStatsdAddress:
C.StatsdAddr = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
C.StatsdAddr = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
case OptionTypeStatsdTagsFormat:
value := opt.Value.(string) // nolint: forcetypeassert
value := opt.Value.(string) //nolint: forcetypeassert
switch value {
case "datadog":
C.StatsdTagsFormat = statsd.TagFormatDatadog
@@ -206,26 +206,26 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
return fmt.Errorf("incorrect statsd tag %s", value)
}
case OptionTypeStatsdTags:
C.StatsdTags = opt.Value.(map[string]string) // nolint: forcetypeassert
C.StatsdTags = opt.Value.(map[string]string) //nolint: forcetypeassert
case OptionTypeWriteBufferSize:
C.WriteBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert
C.WriteBuffer = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert
case OptionTypeReadBufferSize:
C.ReadBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert
C.ReadBuffer = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert
case OptionTypeCloakPort:
C.CloakPort = int(opt.Value.(uint16)) // nolint: forcetypeassert
C.CloakPort = int(opt.Value.(uint16)) //nolint: forcetypeassert
case OptionTypeAntiReplayMaxSize:
C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert
C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert
case OptionTypeMultiplexPerConnection:
C.MultiplexPerConnection = int(opt.Value.(uint)) // nolint: forcetypeassert
C.MultiplexPerConnection = int(opt.Value.(uint)) //nolint: forcetypeassert
case OptionTypeNTPServers:
C.NTPServers = opt.Value.([]string) // nolint: forcetypeassert
C.NTPServers = opt.Value.([]string) //nolint: forcetypeassert
if len(C.NTPServers) == 0 {
return errors.New("ntp server list is empty")
}
case OptionTypeSecret:
C.Secret = opt.Value.([]byte) // nolint: forcetypeassert
C.Secret = opt.Value.([]byte) //nolint: forcetypeassert
case OptionTypeAdtag:
C.AdTag = opt.Value.([]byte) // nolint: forcetypeassert
C.AdTag = opt.Value.([]byte) //nolint: forcetypeassert
default:
return fmt.Errorf("unknown tag %v", opt.Option)
}
+4 -5
View File
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"strings"
@@ -41,12 +40,12 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
Timeout: ifconfigTimeout,
Transport: &http.Transport{
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
return dialer.DialContext(ctx, network, addr) // nolint: wrapcheck
return dialer.DialContext(ctx, network, addr) //nolint: wrapcheck
},
},
}
req, err := http.NewRequest("GET", ifconfigAddress, nil)
req, err := http.NewRequest(http.MethodGet, ifconfigAddress, nil)
if err != nil {
return nil, fmt.Errorf("cannot create a request: %w", err)
}
@@ -54,7 +53,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
resp, err := client.Do(req.WithContext(ctx))
if err != nil {
if resp != nil {
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck
io.Copy(io.Discard, resp.Body) //nolint: errcheck
}
return nil, fmt.Errorf("cannot perform a request: %w", err)
@@ -62,7 +61,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
defer resp.Body.Close()
respDataBytes, err := ioutil.ReadAll(resp.Body)
respDataBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("cannot read response body: %w", err)
}
+7 -6
View File
@@ -8,20 +8,21 @@ import (
)
type URLs struct {
TG string `json:"tg_url"` // nolint: tagliatelle
TMe string `json:"tme_url"` // nolint: tagliatelle
TGQRCode string `json:"tg_qrcode"` // nolint: tagliatelle
TMeQRCode string `json:"tme_qrcode"` // nolint: tagliatelle
TG string `json:"tg_url"` //nolint: tagliatelle
TMe string `json:"tme_url"` //nolint: tagliatelle
TGQRCode string `json:"tg_qrcode"` //nolint: tagliatelle
TMeQRCode string `json:"tme_qrcode"` //nolint: tagliatelle
}
type IPURLs struct {
IPv4 *URLs `json:"ipv4,omitempty"`
IPv6 *URLs `json:"ipv6,omitempty"`
BotSecret string `json:"secret_for_mtproxybot"` // nolint: tagliatelle
BotSecret string `json:"secret_for_mtproxybot"` //nolint: tagliatelle
}
func GetURLs() (urls IPURLs) {
func GetURLs() IPURLs {
secret := ""
urls := IPURLs{}
switch C.SecretMode {
case SecretModeSimple: