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 -1
View File
@@ -16,5 +16,5 @@ func (r *Run) Run(cli *CLI, version string) error {
return fmt.Errorf("cannot init config: %w", err)
}
return runProxy(conf, version)
return runProxy(conf, version)
}
+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))
for _, v := range conf.Network.Proxies {
if value := v.Get(nil); value != nil {
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.'"`
Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"`
Debug bool `kong:"name='debug',short='d',help='Run in debug mode.'"`
Concurrency uint64 `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"`
TCPBuffer string `kong:"name='tcp-buffer',short='b',default='4KB',help='Size of TCP buffer to use.'"`
PreferIP string `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"`
DomainFrontingPort uint64 `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"`
DOHIP net.IP `kong:"name='doh-ip',short='d',default='9.9.9.9',help='IP address of DNS-over-HTTP to use.'"`
Timeout time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"`
AntiReplayCacheSize string `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"`
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.'"` // nolint: lll
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.'"` // nolint: lll
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='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'"` // nolint: lll
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{}
if err := conf.BindTo.Set(s.BindTo); err != nil {
+1 -1
View File
@@ -60,7 +60,7 @@ func (c *Config) Validate() error {
return fmt.Errorf("invalid secret %s", c.Secret.String())
}
if c.BindTo.Get("") == "" {
if c.BindTo.Get("") == "" {
return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
}
+1 -1
View File
@@ -10,7 +10,7 @@ import (
)
type ConfigTestSuite struct {
suite.Suite
suite.Suite
}
func (suite *ConfigTestSuite) ReadConfig(filename string) []byte {
+6 -6
View File
@@ -13,12 +13,12 @@ type TypeBlocklistURI struct {
func (t *TypeBlocklistURI) Set(value string) error {
if stat, err := os.Stat(value); err == nil || os.IsExist(err) {
switch {
case stat.IsDir():
return fmt.Errorf("value is correct filepath but directory")
case stat.Mode().Perm() & 0o400 == 0:
return fmt.Errorf("value is correct filepath but not readable")
}
switch {
case stat.IsDir():
return fmt.Errorf("value is correct filepath but directory")
case stat.Mode().Perm()&0o400 == 0:
return fmt.Errorf("value is correct filepath but not readable")
}
value, err = filepath.Abs(value)
if err != nil {
+3 -3
View File
@@ -102,9 +102,9 @@ func (suite *TypeBlocklistURITestSuite) TestGet() {
value := config.TypeBlocklistURI{}
suite.Equal("/path", value.Get("/path"))
suite.NoError(value.Set("http://lalala.ru"))
suite.Equal("http://lalala.ru", value.Get("/path"))
suite.Equal("http://lalala.ru", value.Get(""))
suite.NoError(value.Set("http://lalala.ru"))
suite.Equal("http://lalala.ru", value.Get("/path"))
suite.Equal("http://lalala.ru", value.Get(""))
}
func TestTypeBlocklistURI(t *testing.T) {
+1 -1
View File
@@ -14,7 +14,7 @@ type TypeBytes struct {
}
func (t *TypeBytes) Set(value string) error {
normalizedValue := typeBytesStringCleaner.Replace(strings.ToUpper(value))
normalizedValue := typeBytesStringCleaner.Replace(strings.ToUpper(value))
parsedValue, err := units.ParseBase2Bytes(normalizedValue)
if err != nil {
+9 -9
View File
@@ -64,20 +64,20 @@ func (suite *TypeBytesTestSuite) TestUnmarshalOk() {
}
func (suite *TypeBytesTestSuite) TestMarshalOk() {
value := typeBytesTestStruct{}
suite.NoError(value.Value.Set("1kib"))
value := typeBytesTestStruct{}
suite.NoError(value.Value.Set("1kib"))
data, err := json.Marshal(value)
suite.NoError(err)
suite.JSONEq(`{"value": "1kib"}`, string(data))
data, err := json.Marshal(value)
suite.NoError(err)
suite.JSONEq(`{"value": "1kib"}`, string(data))
}
func (suite *TypeBytesTestSuite) TestGet() {
value := config.TypeBytes{}
suite.EqualValues(1000, value.Get(1000))
value := config.TypeBytes{}
suite.EqualValues(1000, value.Get(1000))
suite.NoError(value.Set("1mib"))
suite.EqualValues(1048576, value.Get(1000))
suite.NoError(value.Set("1mib"))
suite.EqualValues(1048576, value.Get(1000))
}
func TestTypeBytes(t *testing.T) {
+2 -2
View File
@@ -12,11 +12,11 @@ type TypeConcurrency struct {
func (t *TypeConcurrency) Set(value string) error {
concurrencyValue, err := strconv.ParseUint(value, 10, 64)
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 {
return fmt.Errorf("Value should be >0 (%s)", value)
return fmt.Errorf("value should be >0 (%s)", value)
}
t.Value = uint(concurrencyValue)
+2 -2
View File
@@ -86,12 +86,12 @@ func (suite *TypeDurationTestSuite) TestMarshalOk() {
data, err := json.Marshal(testStruct)
assert.NoError(t, err)
expectedJson, err := json.Marshal(map[string]string{
expectedJSON, err := json.Marshal(map[string]string{
"value": expected,
})
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 {
parsedValue, err := strconv.ParseFloat(value, 64)
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 {
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
+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.JSONEq(`{"value": 1.01}`, string(encodedJson))
suite.JSONEq(`{"value": 1.01}`, string(encodedJSON))
}
func (suite *TypeErrorRateTestSuite) TestGet() {
+1 -1
View File
@@ -15,7 +15,7 @@ func (t *TypeIP) Set(value string) error {
return fmt.Errorf("incorret ip %s", value)
}
t.Value = ip
t.Value = ip
return nil
}
+2 -2
View File
@@ -11,10 +11,10 @@ type TypeMetricPrefix struct {
func (t *TypeMetricPrefix) Set(value string) error {
if ok, err := regexp.MatchString("^[a-z0-9]+$", value); !ok || err != nil {
return fmt.Errorf("incorrect metric prefix %s: %w", value, err)
return fmt.Errorf("incorrect metric prefix %s: %w", value, err)
}
t.Value = value
t.Value = value
return nil
}
+3 -3
View File
@@ -6,7 +6,7 @@ import (
)
type TypePort struct {
Value uint16
Value uint
}
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)
}
t.Value = uint16(portValue)
t.Value = uint(portValue)
return nil
}
func (t TypePort) Get(defaultValue uint16) uint16 {
func (t TypePort) Get(defaultValue uint) uint {
if t.Value == 0 {
return defaultValue
}
+1 -1
View File
@@ -33,7 +33,7 @@ func (t *TypePreferIP) Set(value string) error {
switch value {
case TypePreferIPPreferIPv4, TypePreferIPPreferIPv6,
TypePreferOnlyIPv4, TypePreferOnlyIPv6:
t.Value = value
t.Value = value
return nil
default:
+1 -1
View File
@@ -15,7 +15,7 @@ type TypeProxyURL struct {
func (t *TypeProxyURL) Set(value string) error {
parsedURL, err := url.Parse(value)
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 == "" {
+1 -1
View File
@@ -29,7 +29,7 @@ func (t *TypeStatsdTagFormat) Set(value string) error {
switch lowercasedValue {
case TypeStatsdTagFormatDatadog, TypeStatsdTagFormatInfluxdb,
TypeStatsdTagFormatGraphite:
t.Value = lowercasedValue
t.Value = lowercasedValue
return nil
default:
+9 -9
View File
@@ -55,15 +55,6 @@ type ProxyOpts struct {
// This is an optional setting.
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
// stream.
//
@@ -90,6 +81,15 @@ type ProxyOpts struct {
// This is an optional setting.
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
// DCs of Telegram.
//