Fix lint issues

This commit is contained in:
9seconds
2021-07-30 16:34:00 +03:00
parent c85c88efd6
commit 1050ca0b97
20 changed files with 58 additions and 57 deletions
+1
View File
@@ -51,6 +51,7 @@ func makeNetwork(conf *config.Config, version string) (mtglib.Network, error) {
} }
proxyURLs := make([]*url.URL, 0, len(conf.Network.Proxies)) proxyURLs := make([]*url.URL, 0, len(conf.Network.Proxies))
for _, v := range conf.Network.Proxies { for _, v := range conf.Network.Proxies {
if value := v.Get(nil); value != nil { if value := v.Get(nil); value != nil {
proxyURLs = append(proxyURLs, value) proxyURLs = append(proxyURLs, value)
+9 -9
View File
@@ -13,17 +13,17 @@ type SimpleRun struct {
BindTo string `kong:"arg,required,name='bind-to',help='A host:port to bind proxy to.'"` BindTo string `kong:"arg,required,name='bind-to',help='A host:port to bind proxy to.'"`
Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"` Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"`
Debug bool `kong:"name='debug',short='d',help='Run in debug mode.'"` Debug bool `kong:"name='debug',short='d',help='Run in debug mode.'"` // nolint: lll
Concurrency uint64 `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"` Concurrency uint64 `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"` // nolint: lll
TCPBuffer string `kong:"name='tcp-buffer',short='b',default='4KB',help='Size of TCP buffer to use.'"` TCPBuffer string `kong:"name='tcp-buffer',short='b',default='4KB',help='Size of TCP buffer to use.'"` // nolint: lll
PreferIP string `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"` PreferIP string `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"` // nolint: lll
DomainFrontingPort uint64 `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"` DomainFrontingPort uint64 `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"` // nolint: lll
DOHIP net.IP `kong:"name='doh-ip',short='d',default='9.9.9.9',help='IP address of DNS-over-HTTP to use.'"` DOHIP net.IP `kong:"name='doh-ip',short='n',default='9.9.9.9',help='IP address of DNS-over-HTTP to use.'"` // nolint: lll
Timeout time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"` Timeout time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"` // nolint: lll
AntiReplayCacheSize string `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"` AntiReplayCacheSize string `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"` // nolint: lll
} }
func (s *SimpleRun) Run(cli *CLI, version string) error { func (s *SimpleRun) Run(cli *CLI, version string) error { // nolint: cyclop
conf := &config.Config{} conf := &config.Config{}
if err := conf.BindTo.Set(s.BindTo); err != nil { if err := conf.BindTo.Set(s.BindTo); err != nil {
+1 -1
View File
@@ -16,7 +16,7 @@ func (t *TypeBlocklistURI) Set(value string) error {
switch { switch {
case stat.IsDir(): case stat.IsDir():
return fmt.Errorf("value is correct filepath but directory") return fmt.Errorf("value is correct filepath but directory")
case stat.Mode().Perm() & 0o400 == 0: case stat.Mode().Perm()&0o400 == 0:
return fmt.Errorf("value is correct filepath but not readable") return fmt.Errorf("value is correct filepath but not readable")
} }
+2 -2
View File
@@ -12,11 +12,11 @@ type TypeConcurrency struct {
func (t *TypeConcurrency) Set(value string) error { func (t *TypeConcurrency) Set(value string) error {
concurrencyValue, err := strconv.ParseUint(value, 10, 64) concurrencyValue, err := strconv.ParseUint(value, 10, 64)
if err != nil { if err != nil {
return fmt.Errorf("Value is not uint (%s): %w", value, err) return fmt.Errorf("value is not uint (%s): %w", value, err)
} }
if concurrencyValue == 0 { if concurrencyValue == 0 {
return fmt.Errorf("Value should be >0 (%s)", value) return fmt.Errorf("value should be >0 (%s)", value)
} }
t.Value = uint(concurrencyValue) t.Value = uint(concurrencyValue)
+2 -2
View File
@@ -86,12 +86,12 @@ func (suite *TypeDurationTestSuite) TestMarshalOk() {
data, err := json.Marshal(testStruct) data, err := json.Marshal(testStruct)
assert.NoError(t, err) assert.NoError(t, err)
expectedJson, err := json.Marshal(map[string]string{ expectedJSON, err := json.Marshal(map[string]string{
"value": expected, "value": expected,
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.JSONEq(t, string(expectedJson), string(data)) assert.JSONEq(t, string(expectedJSON), string(data))
}) })
} }
} }
+2 -2
View File
@@ -14,11 +14,11 @@ type TypeErrorRate struct {
func (t *TypeErrorRate) Set(value string) error { func (t *TypeErrorRate) Set(value string) error {
parsedValue, err := strconv.ParseFloat(value, 64) parsedValue, err := strconv.ParseFloat(value, 64)
if err != nil { if err != nil {
return fmt.Errorf("Value is not a float (%s): %w", value, err) return fmt.Errorf("value is not a float (%s): %w", value, err)
} }
if parsedValue <= 0.0 || parsedValue >= 100.0 { if parsedValue <= 0.0 || parsedValue >= 100.0 {
return fmt.Errorf("Value should be 0 < x < 100 (%s)", value) return fmt.Errorf("value should be 0 < x < 100 (%s)", value)
} }
t.Value = parsedValue t.Value = parsedValue
+2 -2
View File
@@ -62,9 +62,9 @@ func (suite *TypeErrorRateTestSuite) TestMarshalOk() {
}, },
} }
encodedJson, err := json.Marshal(testStruct) encodedJSON, err := json.Marshal(testStruct)
suite.NoError(err) suite.NoError(err)
suite.JSONEq(`{"value": 1.01}`, string(encodedJson)) suite.JSONEq(`{"value": 1.01}`, string(encodedJSON))
} }
func (suite *TypeErrorRateTestSuite) TestGet() { func (suite *TypeErrorRateTestSuite) TestGet() {
+3 -3
View File
@@ -6,7 +6,7 @@ import (
) )
type TypePort struct { type TypePort struct {
Value uint16 Value uint
} }
func (t *TypePort) Set(value string) error { func (t *TypePort) Set(value string) error {
@@ -19,12 +19,12 @@ func (t *TypePort) Set(value string) error {
return fmt.Errorf("incorrect port number (%s)", value) return fmt.Errorf("incorrect port number (%s)", value)
} }
t.Value = uint16(portValue) t.Value = uint(portValue)
return nil return nil
} }
func (t TypePort) Get(defaultValue uint16) uint16 { func (t TypePort) Get(defaultValue uint) uint {
if t.Value == 0 { if t.Value == 0 {
return defaultValue return defaultValue
} }
+1 -1
View File
@@ -15,7 +15,7 @@ type TypeProxyURL struct {
func (t *TypeProxyURL) Set(value string) error { func (t *TypeProxyURL) Set(value string) error {
parsedURL, err := url.Parse(value) parsedURL, err := url.Parse(value)
if err != nil { if err != nil {
return fmt.Errorf("Value is not corect URL (%s): %w", value, err) return fmt.Errorf("value is not corect URL (%s): %w", value, err)
} }
if parsedURL.Host == "" { if parsedURL.Host == "" {
+9 -9
View File
@@ -55,15 +55,6 @@ type ProxyOpts struct {
// This is an optional setting. // This is an optional setting.
Concurrency uint Concurrency uint
// DomainFrontingPort is a port we use to connect to a fronting
// domain.
//
// This is required because secret does not specify a port. It
// specifies a hostname only.
//
// This is an optional setting.
DomainFrontingPort uint16
// IdleTimeout is a timeout for relay when we have to break a // IdleTimeout is a timeout for relay when we have to break a
// stream. // stream.
// //
@@ -90,6 +81,15 @@ type ProxyOpts struct {
// This is an optional setting. // This is an optional setting.
PreferIP string PreferIP string
// DomainFrontingPort is a port we use to connect to a fronting
// domain.
//
// This is required because secret does not specify a port. It
// specifies a hostname only.
//
// This is an optional setting.
DomainFrontingPort uint
// UseTestDCs defines if we have to connect to production or to staging // UseTestDCs defines if we have to connect to production or to staging
// DCs of Telegram. // DCs of Telegram.
// //