Przeglądaj źródła

Fix lint issues

tags/v2.1.0^2
9seconds 4 lat temu
rodzic
commit
1050ca0b97

+ 1
- 1
internal/cli/run.go Wyświetl plik

@@ -16,5 +16,5 @@ func (r *Run) Run(cli *CLI, version string) error {
16 16
 		return fmt.Errorf("cannot init config: %w", err)
17 17
 	}
18 18
 
19
-    return runProxy(conf, version)
19
+	return runProxy(conf, version)
20 20
 }

+ 1
- 0
internal/cli/run_proxy.go Wyświetl plik

@@ -51,6 +51,7 @@ func makeNetwork(conf *config.Config, version string) (mtglib.Network, error) {
51 51
 	}
52 52
 
53 53
 	proxyURLs := make([]*url.URL, 0, len(conf.Network.Proxies))
54
+
54 55
 	for _, v := range conf.Network.Proxies {
55 56
 		if value := v.Get(nil); value != nil {
56 57
 			proxyURLs = append(proxyURLs, value)

+ 9
- 9
internal/cli/simple_run.go Wyświetl plik

@@ -13,17 +13,17 @@ type SimpleRun struct {
13 13
 	BindTo string `kong:"arg,required,name='bind-to',help='A host:port to bind proxy to.'"`
14 14
 	Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"`
15 15
 
16
-	Debug               bool          `kong:"name='debug',short='d',help='Run in debug mode.'"`
17
-	Concurrency         uint64        `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"`
18
-	TCPBuffer           string        `kong:"name='tcp-buffer',short='b',default='4KB',help='Size of TCP buffer to use.'"`
19
-	PreferIP            string        `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"`
20
-	DomainFrontingPort  uint64        `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"`
21
-	DOHIP               net.IP        `kong:"name='doh-ip',short='d',default='9.9.9.9',help='IP address of DNS-over-HTTP to use.'"`
22
-	Timeout             time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"`
23
-	AntiReplayCacheSize string        `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"`
16
+	Debug               bool          `kong:"name='debug',short='d',help='Run in debug mode.'"`                                                                        // nolint: lll
17
+	Concurrency         uint64        `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"`                        // nolint: lll
18
+	TCPBuffer           string        `kong:"name='tcp-buffer',short='b',default='4KB',help='Size of TCP buffer to use.'"`                                             // nolint: lll
19
+	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
20
+	DomainFrontingPort  uint64        `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"`                        // nolint: lll
21
+	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
22
+	Timeout             time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"`                                                    // nolint: lll
23
+	AntiReplayCacheSize string        `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"`                         // nolint: lll
24 24
 }
25 25
 
26
-func (s *SimpleRun) Run(cli *CLI, version string) error {
26
+func (s *SimpleRun) Run(cli *CLI, version string) error { // nolint: cyclop
27 27
 	conf := &config.Config{}
28 28
 
29 29
 	if err := conf.BindTo.Set(s.BindTo); err != nil {

+ 1
- 1
internal/config/config.go Wyświetl plik

@@ -60,7 +60,7 @@ func (c *Config) Validate() error {
60 60
 		return fmt.Errorf("invalid secret %s", c.Secret.String())
61 61
 	}
62 62
 
63
-    if c.BindTo.Get("") == "" {
63
+	if c.BindTo.Get("") == "" {
64 64
 		return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
65 65
 	}
66 66
 

+ 1
- 1
internal/config/config_test.go Wyświetl plik

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 type ConfigTestSuite struct {
13
-    suite.Suite
13
+	suite.Suite
14 14
 }
15 15
 
16 16
 func (suite *ConfigTestSuite) ReadConfig(filename string) []byte {

+ 6
- 6
internal/config/type_blocklist_uri.go Wyświetl plik

@@ -13,12 +13,12 @@ type TypeBlocklistURI struct {
13 13
 
14 14
 func (t *TypeBlocklistURI) Set(value string) error {
15 15
 	if stat, err := os.Stat(value); err == nil || os.IsExist(err) {
16
-        switch {
17
-        case stat.IsDir():
18
-            return fmt.Errorf("value is correct filepath but directory")
19
-        case stat.Mode().Perm() & 0o400 == 0:
20
-            return fmt.Errorf("value is correct filepath but not readable")
21
-        }
16
+		switch {
17
+		case stat.IsDir():
18
+			return fmt.Errorf("value is correct filepath but directory")
19
+		case stat.Mode().Perm()&0o400 == 0:
20
+			return fmt.Errorf("value is correct filepath but not readable")
21
+		}
22 22
 
23 23
 		value, err = filepath.Abs(value)
24 24
 		if err != nil {

+ 3
- 3
internal/config/type_blocklist_uri_test.go Wyświetl plik

@@ -102,9 +102,9 @@ func (suite *TypeBlocklistURITestSuite) TestGet() {
102 102
 	value := config.TypeBlocklistURI{}
103 103
 	suite.Equal("/path", value.Get("/path"))
104 104
 
105
-    suite.NoError(value.Set("http://lalala.ru"))
106
-    suite.Equal("http://lalala.ru", value.Get("/path"))
107
-    suite.Equal("http://lalala.ru", value.Get(""))
105
+	suite.NoError(value.Set("http://lalala.ru"))
106
+	suite.Equal("http://lalala.ru", value.Get("/path"))
107
+	suite.Equal("http://lalala.ru", value.Get(""))
108 108
 }
109 109
 
110 110
 func TestTypeBlocklistURI(t *testing.T) {

+ 1
- 1
internal/config/type_bytes.go Wyświetl plik

@@ -14,7 +14,7 @@ type TypeBytes struct {
14 14
 }
15 15
 
16 16
 func (t *TypeBytes) Set(value string) error {
17
-    normalizedValue := typeBytesStringCleaner.Replace(strings.ToUpper(value))
17
+	normalizedValue := typeBytesStringCleaner.Replace(strings.ToUpper(value))
18 18
 
19 19
 	parsedValue, err := units.ParseBase2Bytes(normalizedValue)
20 20
 	if err != nil {

+ 9
- 9
internal/config/type_bytes_test.go Wyświetl plik

@@ -64,20 +64,20 @@ func (suite *TypeBytesTestSuite) TestUnmarshalOk() {
64 64
 }
65 65
 
66 66
 func (suite *TypeBytesTestSuite) TestMarshalOk() {
67
-    value := typeBytesTestStruct{}
68
-    suite.NoError(value.Value.Set("1kib"))
67
+	value := typeBytesTestStruct{}
68
+	suite.NoError(value.Value.Set("1kib"))
69 69
 
70
-    data, err := json.Marshal(value)
71
-    suite.NoError(err)
72
-    suite.JSONEq(`{"value": "1kib"}`, string(data))
70
+	data, err := json.Marshal(value)
71
+	suite.NoError(err)
72
+	suite.JSONEq(`{"value": "1kib"}`, string(data))
73 73
 }
74 74
 
75 75
 func (suite *TypeBytesTestSuite) TestGet() {
76
-    value := config.TypeBytes{}
77
-    suite.EqualValues(1000, value.Get(1000))
76
+	value := config.TypeBytes{}
77
+	suite.EqualValues(1000, value.Get(1000))
78 78
 
79
-    suite.NoError(value.Set("1mib"))
80
-    suite.EqualValues(1048576, value.Get(1000))
79
+	suite.NoError(value.Set("1mib"))
80
+	suite.EqualValues(1048576, value.Get(1000))
81 81
 }
82 82
 
83 83
 func TestTypeBytes(t *testing.T) {

+ 2
- 2
internal/config/type_concurrency.go Wyświetl plik

@@ -12,11 +12,11 @@ type TypeConcurrency struct {
12 12
 func (t *TypeConcurrency) Set(value string) error {
13 13
 	concurrencyValue, err := strconv.ParseUint(value, 10, 64)
14 14
 	if err != nil {
15
-		return fmt.Errorf("Value is not uint (%s): %w", value, err)
15
+		return fmt.Errorf("value is not uint (%s): %w", value, err)
16 16
 	}
17 17
 
18 18
 	if concurrencyValue == 0 {
19
-		return fmt.Errorf("Value should be >0 (%s)", value)
19
+		return fmt.Errorf("value should be >0 (%s)", value)
20 20
 	}
21 21
 
22 22
 	t.Value = uint(concurrencyValue)

+ 2
- 2
internal/config/type_duration_test.go Wyświetl plik

@@ -86,12 +86,12 @@ func (suite *TypeDurationTestSuite) TestMarshalOk() {
86 86
 			data, err := json.Marshal(testStruct)
87 87
 			assert.NoError(t, err)
88 88
 
89
-			expectedJson, err := json.Marshal(map[string]string{
89
+			expectedJSON, err := json.Marshal(map[string]string{
90 90
 				"value": expected,
91 91
 			})
92 92
 			assert.NoError(t, err)
93 93
 
94
-			assert.JSONEq(t, string(expectedJson), string(data))
94
+			assert.JSONEq(t, string(expectedJSON), string(data))
95 95
 		})
96 96
 	}
97 97
 }

+ 2
- 2
internal/config/type_error_rate.go Wyświetl plik

@@ -14,11 +14,11 @@ type TypeErrorRate struct {
14 14
 func (t *TypeErrorRate) Set(value string) error {
15 15
 	parsedValue, err := strconv.ParseFloat(value, 64)
16 16
 	if err != nil {
17
-		return fmt.Errorf("Value is not a float (%s): %w", value, err)
17
+		return fmt.Errorf("value is not a float (%s): %w", value, err)
18 18
 	}
19 19
 
20 20
 	if parsedValue <= 0.0 || parsedValue >= 100.0 {
21
-		return fmt.Errorf("Value should be 0 < x < 100 (%s)", value)
21
+		return fmt.Errorf("value should be 0 < x < 100 (%s)", value)
22 22
 	}
23 23
 
24 24
 	t.Value = parsedValue

+ 2
- 2
internal/config/type_error_rate_test.go Wyświetl plik

@@ -62,9 +62,9 @@ func (suite *TypeErrorRateTestSuite) TestMarshalOk() {
62 62
 		},
63 63
 	}
64 64
 
65
-	encodedJson, err := json.Marshal(testStruct)
65
+	encodedJSON, err := json.Marshal(testStruct)
66 66
 	suite.NoError(err)
67
-	suite.JSONEq(`{"value": 1.01}`, string(encodedJson))
67
+	suite.JSONEq(`{"value": 1.01}`, string(encodedJSON))
68 68
 }
69 69
 
70 70
 func (suite *TypeErrorRateTestSuite) TestGet() {

+ 1
- 1
internal/config/type_ip.go Wyświetl plik

@@ -15,7 +15,7 @@ func (t *TypeIP) Set(value string) error {
15 15
 		return fmt.Errorf("incorret ip %s", value)
16 16
 	}
17 17
 
18
-    t.Value = ip
18
+	t.Value = ip
19 19
 
20 20
 	return nil
21 21
 }

+ 2
- 2
internal/config/type_metric_prefix.go Wyświetl plik

@@ -11,10 +11,10 @@ type TypeMetricPrefix struct {
11 11
 
12 12
 func (t *TypeMetricPrefix) Set(value string) error {
13 13
 	if ok, err := regexp.MatchString("^[a-z0-9]+$", value); !ok || err != nil {
14
-        return fmt.Errorf("incorrect metric prefix %s: %w", value, err)
14
+		return fmt.Errorf("incorrect metric prefix %s: %w", value, err)
15 15
 	}
16 16
 
17
-    t.Value = value
17
+	t.Value = value
18 18
 
19 19
 	return nil
20 20
 }

+ 3
- 3
internal/config/type_port.go Wyświetl plik

@@ -6,7 +6,7 @@ import (
6 6
 )
7 7
 
8 8
 type TypePort struct {
9
-	Value uint16
9
+	Value uint
10 10
 }
11 11
 
12 12
 func (t *TypePort) Set(value string) error {
@@ -19,12 +19,12 @@ func (t *TypePort) Set(value string) error {
19 19
 		return fmt.Errorf("incorrect port number (%s)", value)
20 20
 	}
21 21
 
22
-    t.Value = uint16(portValue)
22
+	t.Value = uint(portValue)
23 23
 
24 24
 	return nil
25 25
 }
26 26
 
27
-func (t TypePort) Get(defaultValue uint16) uint16 {
27
+func (t TypePort) Get(defaultValue uint) uint {
28 28
 	if t.Value == 0 {
29 29
 		return defaultValue
30 30
 	}

+ 1
- 1
internal/config/type_prefer_ip.go Wyświetl plik

@@ -33,7 +33,7 @@ func (t *TypePreferIP) Set(value string) error {
33 33
 	switch value {
34 34
 	case TypePreferIPPreferIPv4, TypePreferIPPreferIPv6,
35 35
 		TypePreferOnlyIPv4, TypePreferOnlyIPv6:
36
-        t.Value = value
36
+		t.Value = value
37 37
 
38 38
 		return nil
39 39
 	default:

+ 1
- 1
internal/config/type_proxy_url.go Wyświetl plik

@@ -15,7 +15,7 @@ type TypeProxyURL struct {
15 15
 func (t *TypeProxyURL) Set(value string) error {
16 16
 	parsedURL, err := url.Parse(value)
17 17
 	if err != nil {
18
-		return fmt.Errorf("Value is not corect URL (%s): %w", value, err)
18
+		return fmt.Errorf("value is not corect URL (%s): %w", value, err)
19 19
 	}
20 20
 
21 21
 	if parsedURL.Host == "" {

+ 1
- 1
internal/config/type_statsd_tag_format.go Wyświetl plik

@@ -29,7 +29,7 @@ func (t *TypeStatsdTagFormat) Set(value string) error {
29 29
 	switch lowercasedValue {
30 30
 	case TypeStatsdTagFormatDatadog, TypeStatsdTagFormatInfluxdb,
31 31
 		TypeStatsdTagFormatGraphite:
32
-        t.Value = lowercasedValue
32
+		t.Value = lowercasedValue
33 33
 
34 34
 		return nil
35 35
 	default:

+ 9
- 9
mtglib/proxy_opts.go Wyświetl plik

@@ -55,15 +55,6 @@ type ProxyOpts struct {
55 55
 	// This is an optional setting.
56 56
 	Concurrency uint
57 57
 
58
-	// DomainFrontingPort is a port we use to connect to a fronting
59
-	// domain.
60
-	//
61
-	// This is required because secret does not specify a port. It
62
-	// specifies a hostname only.
63
-	//
64
-	// This is an optional setting.
65
-	DomainFrontingPort uint16
66
-
67 58
 	// IdleTimeout is a timeout for relay when we have to break a
68 59
 	// stream.
69 60
 	//
@@ -90,6 +81,15 @@ type ProxyOpts struct {
90 81
 	// This is an optional setting.
91 82
 	PreferIP string
92 83
 
84
+	// DomainFrontingPort is a port we use to connect to a fronting
85
+	// domain.
86
+	//
87
+	// This is required because secret does not specify a port. It
88
+	// specifies a hostname only.
89
+	//
90
+	// This is an optional setting.
91
+	DomainFrontingPort uint
92
+
93 93
 	// UseTestDCs defines if we have to connect to production or to staging
94 94
 	// DCs of Telegram.
95 95
 	//

Ładowanie…
Anuluj
Zapisz