diff --git a/internal/cli/run.go b/internal/cli/run.go index 644f349..390f30a 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -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) } diff --git a/internal/cli/run_proxy.go b/internal/cli/run_proxy.go index 4716bc1..745319f 100644 --- a/internal/cli/run_proxy.go +++ b/internal/cli/run_proxy.go @@ -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) diff --git a/internal/cli/simple_run.go b/internal/cli/simple_run.go index 167b9c4..4d1726a 100644 --- a/internal/cli/simple_run.go +++ b/internal/cli/simple_run.go @@ -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 { diff --git a/internal/config/config.go b/internal/config/config.go index c05d33f..6230758 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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()) } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index f191221..e6b19e0 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -10,7 +10,7 @@ import ( ) type ConfigTestSuite struct { - suite.Suite + suite.Suite } func (suite *ConfigTestSuite) ReadConfig(filename string) []byte { diff --git a/internal/config/type_blocklist_uri.go b/internal/config/type_blocklist_uri.go index 8bd3677..620ea51 100644 --- a/internal/config/type_blocklist_uri.go +++ b/internal/config/type_blocklist_uri.go @@ -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 { diff --git a/internal/config/type_blocklist_uri_test.go b/internal/config/type_blocklist_uri_test.go index 407beda..3cf76bc 100644 --- a/internal/config/type_blocklist_uri_test.go +++ b/internal/config/type_blocklist_uri_test.go @@ -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) { diff --git a/internal/config/type_bytes.go b/internal/config/type_bytes.go index 412f019..254d556 100644 --- a/internal/config/type_bytes.go +++ b/internal/config/type_bytes.go @@ -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 { diff --git a/internal/config/type_bytes_test.go b/internal/config/type_bytes_test.go index 08874f4..bee0922 100644 --- a/internal/config/type_bytes_test.go +++ b/internal/config/type_bytes_test.go @@ -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) { diff --git a/internal/config/type_concurrency.go b/internal/config/type_concurrency.go index 1c172d7..4f39b3b 100644 --- a/internal/config/type_concurrency.go +++ b/internal/config/type_concurrency.go @@ -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) diff --git a/internal/config/type_duration_test.go b/internal/config/type_duration_test.go index 49d674a..5d0e204 100644 --- a/internal/config/type_duration_test.go +++ b/internal/config/type_duration_test.go @@ -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)) }) } } diff --git a/internal/config/type_error_rate.go b/internal/config/type_error_rate.go index e950424..4e30e09 100644 --- a/internal/config/type_error_rate.go +++ b/internal/config/type_error_rate.go @@ -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 diff --git a/internal/config/type_error_rate_test.go b/internal/config/type_error_rate_test.go index c45ffa7..44d17c2 100644 --- a/internal/config/type_error_rate_test.go +++ b/internal/config/type_error_rate_test.go @@ -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() { diff --git a/internal/config/type_ip.go b/internal/config/type_ip.go index 03a2f20..c637181 100644 --- a/internal/config/type_ip.go +++ b/internal/config/type_ip.go @@ -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 } diff --git a/internal/config/type_metric_prefix.go b/internal/config/type_metric_prefix.go index fcd951e..e55438c 100644 --- a/internal/config/type_metric_prefix.go +++ b/internal/config/type_metric_prefix.go @@ -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 } diff --git a/internal/config/type_port.go b/internal/config/type_port.go index f53d77e..cdab9ee 100644 --- a/internal/config/type_port.go +++ b/internal/config/type_port.go @@ -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 } diff --git a/internal/config/type_prefer_ip.go b/internal/config/type_prefer_ip.go index b28a33f..8a07721 100644 --- a/internal/config/type_prefer_ip.go +++ b/internal/config/type_prefer_ip.go @@ -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: diff --git a/internal/config/type_proxy_url.go b/internal/config/type_proxy_url.go index f27d0af..f3d0231 100644 --- a/internal/config/type_proxy_url.go +++ b/internal/config/type_proxy_url.go @@ -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 == "" { diff --git a/internal/config/type_statsd_tag_format.go b/internal/config/type_statsd_tag_format.go index e449b9f..5301903 100644 --- a/internal/config/type_statsd_tag_format.go +++ b/internal/config/type_statsd_tag_format.go @@ -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: diff --git a/mtglib/proxy_opts.go b/mtglib/proxy_opts.go index d747286..2eac74e 100644 --- a/mtglib/proxy_opts.go +++ b/mtglib/proxy_opts.go @@ -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. //