Procházet zdrojové kódy

Merge remote-tracking branch 'origin/master' into stable

tags/v2.1.0
9seconds před 4 roky
rodič
revize
8758208de6
77 změnil soubory, kde provedl 2015 přidání a 2087 odebrání
  1. 1
    1
      .github/workflows/ci.yaml
  2. 1
    1
      Makefile
  3. 44
    0
      README.md
  4. 11
    10
      go.mod
  5. 274
    236
      go.sum
  6. 36
    45
      internal/cli/access.go
  7. 0
    197
      internal/cli/access_test.go
  8. 0
    81
      internal/cli/base.go
  9. 0
    33
      internal/cli/base_internal_test.go
  10. 2
    1
      internal/cli/cli.go
  11. 2
    2
      internal/cli/generate_secret.go
  12. 0
    51
      internal/cli/generate_secret_test.go
  13. 0
    37
      internal/cli/init_test.go
  14. 0
    167
      internal/cli/proxy.go
  15. 20
    0
      internal/cli/run.go
  16. 209
    0
      internal/cli/run_proxy.go
  17. 81
    0
      internal/cli/simple_run.go
  18. 25
    101
      internal/config/config.go
  19. 80
    0
      internal/config/parse.go
  20. 36
    27
      internal/config/type_blocklist_uri.go
  21. 37
    101
      internal/config/type_blocklist_uri_test.go
  22. 37
    0
      internal/config/type_bool.go
  23. 107
    0
      internal/config/type_bool_test.go
  24. 25
    24
      internal/config/type_bytes.go
  25. 11
    45
      internal/config/type_bytes_test.go
  26. 45
    0
      internal/config/type_concurrency.go
  27. 73
    0
      internal/config/type_concurrency_test.go
  28. 26
    19
      internal/config/type_duration.go
  29. 33
    41
      internal/config/type_duration_test.go
  30. 20
    16
      internal/config/type_error_rate.go
  31. 33
    77
      internal/config/type_error_rate_test.go
  32. 30
    34
      internal/config/type_hostport.go
  33. 21
    48
      internal/config/type_hostport_test.go
  34. 16
    18
      internal/config/type_http_path.go
  35. 24
    48
      internal/config/type_http_path_test.go
  36. 20
    20
      internal/config/type_ip.go
  37. 33
    44
      internal/config/type_ip_test.go
  38. 18
    19
      internal/config/type_metric_prefix.go
  39. 20
    65
      internal/config/type_metric_prefix_test.go
  40. 20
    20
      internal/config/type_port.go
  41. 24
    70
      internal/config/type_port_test.go
  42. 35
    23
      internal/config/type_prefer_ip.go
  43. 28
    57
      internal/config/type_prefer_ip_test.go
  44. 61
    0
      internal/config/type_proxy_url.go
  45. 96
    0
      internal/config/type_proxy_url_test.go
  46. 31
    22
      internal/config/type_statsd_tag_format.go
  47. 30
    58
      internal/config/type_statsd_tag_format_test.go
  48. 0
    71
      internal/config/type_url.go
  49. 0
    107
      internal/config/type_url_test.go
  50. 19
    0
      internal/utils/make_qr_code_url.go
  51. 31
    0
      internal/utils/make_qr_code_url_test.go
  52. 26
    0
      internal/utils/read_config.go
  53. 55
    0
      internal/utils/read_config_test.go
  54. 1
    0
      internal/utils/testdata/broken.toml
  55. 0
    0
      internal/utils/testdata/empty.toml
  56. 0
    0
      internal/utils/testdata/minimal.toml
  57. 2
    0
      internal/utils/testdata/missed-bindto.toml
  58. 1
    0
      internal/utils/testdata/missed-secret.toml
  59. 2
    2
      ipblocklist/firehol.go
  60. 2
    2
      mtglib/internal/faketls/client_hello_test.go
  61. 22
    4
      mtglib/internal/faketls/init.go
  62. 18
    2
      mtglib/internal/faketls/record/init.go
  63. 2
    2
      mtglib/internal/faketls/testdata/client-hello-bad-fa2e46cdb33e2a1b.json
  64. 3
    3
      mtglib/internal/faketls/testdata/client-hello-ok-19dfe38384b9884b.json
  65. 3
    3
      mtglib/internal/faketls/testdata/client-hello-ok-48f8a72a56f3174a.json
  66. 3
    3
      mtglib/internal/faketls/testdata/client-hello-ok-651054256093c6cd.json
  67. 3
    3
      mtglib/internal/faketls/testdata/client-hello-ok-79d01ef18a9d2621.json
  68. 3
    3
      mtglib/internal/faketls/testdata/client-hello-ok-7a5569f05b118145.json
  69. 2
    0
      mtglib/internal/obfuscated2/handshake_frame.go
  70. 9
    9
      mtglib/proxy_opts.go
  71. 1
    1
      mtglib/proxy_test.go
  72. 5
    2
      mtglib/secret.go
  73. 8
    2
      network/init.go
  74. 2
    2
      network/network_test.go
  75. 1
    1
      network/proxy_dialer.go
  76. 13
    3
      stats/init.go
  77. 2
    3
      stats/prometheus.go

+ 1
- 1
.github/workflows/ci.yaml Zobrazit soubor

@@ -70,7 +70,7 @@ jobs:
70 70
       - name: Run linter
71 71
         uses: golangci/golangci-lint-action@v2
72 72
         with:
73
-          version: v1.39.0
73
+          version: v1.41.1
74 74
 
75 75
   docker:
76 76
     name: Docker

+ 1
- 1
Makefile Zobrazit soubor

@@ -2,7 +2,7 @@ ROOT_DIR     := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2 2
 IMAGE_NAME   := mtg
3 3
 APP_NAME     := $(IMAGE_NAME)
4 4
 
5
-GOLANGCI_LINT_VERSION := v1.39.0
5
+GOLANGCI_LINT_VERSION := v1.41.1
6 6
 
7 7
 VERSION_GO         := $(shell go version)
8 8
 VERSION_DATE       := $(shell date -Ru)

+ 44
- 0
README.md Zobrazit soubor

@@ -237,6 +237,50 @@ For example, you've bought a VPS from [Digital
237 237
 Ocean](https://www.digitalocean.com/). Then it might be a good idea to
238 238
 generate a secret for _digitalocean.com_ then.
239 239
 
240
+
241
+### Simple run mode
242
+
243
+mtg supports 2 modes: simple and normal. Simple mode allows starting
244
+proxy with a small subset of configuration options you usually want to
245
+modify. This is quite good for oneliners that you can copy-paste and do
246
+not bother about external files whatsoever.
247
+
248
+Let's take a look:
249
+
250
+```console
251
+Usage: mtg simple-run <bind-to> <secret>
252
+
253
+Run proxy without config file.
254
+
255
+Arguments:
256
+  <bind-to>    A host:port to bind proxy to.
257
+  <secret>     Proxy secret.
258
+
259
+Flags:
260
+  -h, --help                           Show context-sensitive help.
261
+  -v, --version                        Print version.
262
+
263
+  -d, --debug                          Run in debug mode.
264
+  -c, --concurrency=8192               Max number of concurrent connection to proxy.
265
+  -b, --tcp-buffer="4KB"               Size of TCP buffer to use.
266
+  -i, --prefer-ip="prefer-ipv6"        IP preference. By default we prefer IPv6 with fallback to IPv4.
267
+  -p, --domain-fronting-port=443       A port to access for domain fronting.
268
+  -n, --doh-ip=9.9.9.9                 IP address of DNS-over-HTTP to use.
269
+  -t, --timeout=10s                    Network timeout to use
270
+  -a, --antireplay-cache-size="1MB"    A size of anti-replay cache to use.
271
+```
272
+
273
+So, if you want to startup a proxy with CLI only, you can do something like
274
+
275
+```console
276
+$ mtg simple-run -n 1.1.1.1 -t 30s -a 512kib 127.0.0.1:3128 7hBO-dCS4EBzenlKbdLFxyNnb29nbGUuY29t
277
+```
278
+
279
+The rest of the configuration will be taken from default values. But
280
+a simple run is fine if you do not have any special requirements or
281
+granular tuning. If you want it, please checkout the configuration
282
+files.
283
+
240 284
 ### Prepare a configuration file
241 285
 
242 286
 Please checkout an example configuration file. All options except of

+ 11
- 10
go.mod Zobrazit soubor

@@ -4,7 +4,7 @@ go 1.16
4 4
 
5 5
 require (
6 6
 	github.com/OneOfOne/xxhash v1.2.8
7
-	github.com/alecthomas/kong v0.2.16
7
+	github.com/alecthomas/kong v0.2.17
8 8
 	github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15
9 9
 	github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
10 10
 	github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6
@@ -15,17 +15,18 @@ require (
15 15
 	github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1
16 16
 	github.com/libp2p/go-reuseport v0.0.2
17 17
 	github.com/mccutchen/go-httpbin v1.1.1
18
-	github.com/panjf2000/ants/v2 v2.4.4
19
-	github.com/pelletier/go-toml v1.9.1
20
-	github.com/prometheus/client_golang v1.10.0
21
-	github.com/prometheus/common v0.24.0 // indirect
22
-	github.com/rs/zerolog v1.22.0
18
+	github.com/panjf2000/ants/v2 v2.4.6
19
+	github.com/pelletier/go-toml v1.9.3
20
+	github.com/prometheus/client_golang v1.11.0
21
+	github.com/prometheus/common v0.30.0 // indirect
22
+	github.com/prometheus/procfs v0.7.1 // indirect
23
+	github.com/rs/zerolog v1.23.0
23 24
 	github.com/smira/go-statsd v1.3.2
24 25
 	github.com/stretchr/objx v0.3.0 // indirect
25 26
 	github.com/stretchr/testify v1.7.0
26 27
 	github.com/tylertreat/BoomFilters v0.0.0-20210315201527-1a82519a3e43
27
-	github.com/xeipuuv/gojsonschema v1.2.0
28
-	golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
29
-	golang.org/x/net v0.0.0-20210510120150-4163338589ed
30
-	golang.org/x/sys v0.0.0-20210514084401-e8d321eab015
28
+	golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
29
+	golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985
30
+	golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
31
+	google.golang.org/protobuf v1.27.1 // indirect
31 32
 )

+ 274
- 236
go.sum Zobrazit soubor

@@ -1,17 +1,44 @@
1 1
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2 2
 cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
3
+cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
4
+cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
5
+cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
6
+cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
7
+cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
8
+cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To=
9
+cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4=
10
+cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M=
11
+cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc=
12
+cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk=
13
+cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs=
14
+cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc=
15
+cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY=
16
+cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
17
+cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
18
+cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
19
+cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg=
20
+cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc=
21
+cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
22
+cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
23
+cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
24
+cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
25
+cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
26
+cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA=
27
+cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU=
28
+cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
29
+cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
30
+cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
31
+cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
32
+cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
33
+dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3 34
 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
4 35
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
5
-github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
36
+github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
6 37
 github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
7 38
 github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
8 39
 github.com/PuerkitoBio/goquery v1.6.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
9
-github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
10
-github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
11
-github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
12
-github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
13
-github.com/alecthomas/kong v0.2.16 h1:F232CiYSn54Tnl1sJGTeHmx4vJDNLVP2b9yCVMOQwHQ=
14
-github.com/alecthomas/kong v0.2.16/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
40
+github.com/alecthomas/kong v0.2.17 h1:URDISCI96MIgcIlQyoCAlhOmrSw6pZScBNkctg8r0W0=
41
+github.com/alecthomas/kong v0.2.17/go.mod h1:ka3VZ8GZNPXv9Ov+j4YNLkI8mTuhXyr/0ktSlqIydQQ=
15 42
 github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
16 43
 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
17 44
 github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -21,109 +48,100 @@ github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 h1:AUNCr9CiJuwrRY
21 48
 github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
22 49
 github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg=
23 50
 github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
24
-github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
25
-github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
26
-github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
27
-github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
28
-github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
29 51
 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
30 52
 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
31
-github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
32
-github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
33
-github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
34
-github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
35 53
 github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6 h1:4NNbNM2Iq/k57qEu7WfL67UrbPq1uFWxW4qODCohi+0=
36 54
 github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6/go.mod h1:J29hk+f9lJrblVIfiJOtTFk+OblBawmib4uz/VdKzlg=
37 55
 github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
38 56
 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
39 57
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
40 58
 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
41
-github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
42
-github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
43
-github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
44
-github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
45 59
 github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
46 60
 github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
47 61
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
48 62
 github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
49 63
 github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
50
-github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
64
+github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
65
+github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
66
+github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
51 67
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
52
-github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
53
-github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
54
-github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
55
-github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
56
-github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
57
-github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
58
-github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
59
-github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
68
+github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
69
+github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
60 70
 github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U=
61 71
 github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
62 72
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
63 73
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
64 74
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
65
-github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
66
-github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
67
-github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
68
-github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
69
-github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
70
-github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
71
-github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
75
+github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
72 76
 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
77
+github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
73 78
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
74
-github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
75
-github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
76
-github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
77
-github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
78
-github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
79
+github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
80
+github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
81
+github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
79 82
 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
80 83
 github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
81
-github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
84
+github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
82 85
 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
83 86
 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
84 87
 github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
85 88
 github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
86
-github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
87 89
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
88
-github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
90
+github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
89 91
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
90
-github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
91
-github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
92 92
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
93
-github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
94 93
 github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
94
+github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
95
+github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
95 96
 github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
97
+github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
98
+github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
99
+github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
100
+github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
101
+github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
102
+github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
96 103
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
97 104
 github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
98 105
 github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
106
+github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
107
+github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
108
+github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
99 109
 github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
100 110
 github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
101 111
 github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
102 112
 github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
103 113
 github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
114
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
104 115
 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
105 116
 github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
106 117
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
107 118
 github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
108 119
 github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
109
-github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
110 120
 github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
111 121
 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
112 122
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
113 123
 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
114 124
 github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
115 125
 github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
126
+github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
127
+github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
128
+github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
116 129
 github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
117 130
 github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
118 131
 github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
119 132
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
133
+github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
134
+github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
135
+github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
136
+github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
137
+github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
138
+github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
139
+github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
140
+github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
141
+github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
120 142
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
121
-github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
122
-github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
123
-github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
124
-github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
125
-github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
126
-github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
143
+github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
144
+github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
127 145
 github.com/gotd/getdoc v0.6.2/go.mod h1:6Ul8cyaq+Aw0gVyuU+TKZPCmNjdlylzSIWVxjzI5t/U=
128 146
 github.com/gotd/ige v0.1.5 h1:qITql4hZpqPM/DSeO5IVlxzXJxrs4ZZiKRwPif2K76U=
129 147
 github.com/gotd/ige v0.1.5/go.mod h1:LbvqjUuGELVuHcKjfJZ2NPNzegICQU4eqrPAkXy0nTs=
@@ -135,50 +153,23 @@ github.com/gotd/tl v0.4.0/go.mod h1:CMIcjPWFS4qxxJ+1Ce7U/ilbtPrkoVo/t8uhN5Y/D7c=
135 153
 github.com/gotd/xor v0.1.0/go.mod h1:ZTmdgqf6SOHder8/MFp9CNkXIadzID5lIiaZxRZICH0=
136 154
 github.com/gotd/xor v0.1.1 h1:LSPEeuf7noTo4fi4PrEsAaWXOSwjsY2e+IINPiR+c7s=
137 155
 github.com/gotd/xor v0.1.1/go.mod h1:ZTmdgqf6SOHder8/MFp9CNkXIadzID5lIiaZxRZICH0=
138
-github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
139
-github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
140
-github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
141
-github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
142
-github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
143
-github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
144
-github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
145
-github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
146
-github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
147
-github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
148
-github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
149
-github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
150
-github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
151
-github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
152
-github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
153
-github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
154
-github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
155 156
 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
156 157
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
157
-github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
158
-github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
159
-github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
160
-github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
161
-github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
162
-github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
163
-github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
164
-github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
158
+github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
165 159
 github.com/jarcoal/httpmock v1.0.8 h1:8kI16SoO6LQKgPE7PvQuV+YuD/inwHd7fOOe2zMbo4k=
166 160
 github.com/jarcoal/httpmock v1.0.8/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
167
-github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
168
-github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
169 161
 github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
170 162
 github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
171
-github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
172
-github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
173 163
 github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
174
-github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
164
+github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
165
+github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
166
+github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
175 167
 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
176 168
 github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
177 169
 github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
178 170
 github.com/k0kubun/pp v2.4.0+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
179 171
 github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1 h1:D7qhJP3R49ZjUzpzKQ6B2H3lgejPs6DTO5gRomhhOpE=
180 172
 github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1/go.mod h1:2OfLA+0esiUJpwMjrH39pEk79cb8MvGTBS9YlZpejJ4=
181
-github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
182 173
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
183 174
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
184 175
 github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -190,133 +181,65 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
190 181
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
191 182
 github.com/libp2p/go-reuseport v0.0.2 h1:XSG94b1FJfGA01BUrT82imejHQyTxO4jEWqheyCXYvU=
192 183
 github.com/libp2p/go-reuseport v0.0.2/go.mod h1:SPD+5RwGC7rcnzngoYC86GjPzjSywuQyMVAheVBD9nQ=
193
-github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
194
-github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
195
-github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
196
-github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
197 184
 github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
198
-github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
199
-github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
200 185
 github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
201 186
 github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
202
-github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
203 187
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
204 188
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
205 189
 github.com/mccutchen/go-httpbin v1.1.1 h1:aEws49HEJEyXHLDnshQVswfUlCVoS8g6h9YaDyaW7RE=
206 190
 github.com/mccutchen/go-httpbin v1.1.1/go.mod h1:fhpOYavp5g2K74XDl/ao2y4KvhqVtKlkg1e+0UaQv7I=
207
-github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
208
-github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
209
-github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
210
-github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
211
-github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
212
-github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
213
-github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
214
-github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
215 191
 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
216 192
 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
217 193
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
218 194
 github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
219 195
 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
220 196
 github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
221
-github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
222
-github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
223
-github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
224
-github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
225
-github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
226
-github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
227
-github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
228
-github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
229
-github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
230
-github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
231
-github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
232
-github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
233
-github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
234
-github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
235
-github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
236
-github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
237
-github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
238
-github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
239
-github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
240
-github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
241
-github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
242
-github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
243
-github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
244
-github.com/panjf2000/ants/v2 v2.4.4 h1:kebk2KSiXHGeiYS6b+w2RqNN5+IKoqlBNd7cuC7MvQI=
245
-github.com/panjf2000/ants/v2 v2.4.4/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
246
-github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
247
-github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
248
-github.com/pelletier/go-toml v1.9.1 h1:a6qW1EVNZWH9WGI6CsYdD8WAylkoXBS5yv0XHlh17Tc=
249
-github.com/pelletier/go-toml v1.9.1/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
250
-github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
251
-github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
252
-github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
197
+github.com/panjf2000/ants/v2 v2.4.6 h1:drmj9mcygn2gawZ155dRbo+NfXEfAssjZNU1qoIb4gQ=
198
+github.com/panjf2000/ants/v2 v2.4.6/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
199
+github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
200
+github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
253 201
 github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
254 202
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
255 203
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
256 204
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
257 205
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
258
-github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
259 206
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
260 207
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
261
-github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
262 208
 github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
263
-github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
264 209
 github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
265
-github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
266 210
 github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
267
-github.com/prometheus/client_golang v1.10.0 h1:/o0BDeWzLWXNZ+4q5gXltUvaMpJqckTa+jTNoB+z4cg=
268
-github.com/prometheus/client_golang v1.10.0/go.mod h1:WJM3cc3yu7XKBKa/I8WeZm+V3eltZnBwfENSU7mdogU=
211
+github.com/prometheus/client_golang v1.11.0 h1:HNkLOAEQMIDv/K+04rukrLx6ch7msSRwf3/SASFAGtQ=
212
+github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
269 213
 github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
270
-github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
271 214
 github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
272 215
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
273
-github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
274 216
 github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
275 217
 github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
276
-github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
277 218
 github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
278
-github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
279 219
 github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
280
-github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
281
-github.com/prometheus/common v0.24.0 h1:aIycr3wRFxPUq8XlLQlGQ9aNXV3dFi5y62pe/SB262k=
282
-github.com/prometheus/common v0.24.0/go.mod h1:H6QK/N6XVT42whUeIdI3dp36w49c+/iMDk7UAI2qm7Q=
220
+github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
221
+github.com/prometheus/common v0.30.0 h1:JEkYlQnpzrzQFxi6gnukFPdQ+ac82oRhzMcIduJu/Ug=
222
+github.com/prometheus/common v0.30.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
283 223
 github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
284
-github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
285 224
 github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
286
-github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
287 225
 github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
288
-github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
289 226
 github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
227
+github.com/prometheus/procfs v0.7.1 h1:TlEtJq5GvGqMykEwWzbZWjjztF86swFhsPix1i0bkgA=
228
+github.com/prometheus/procfs v0.7.1/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
290 229
 github.com/quasilyte/go-ruleguard/dsl v0.3.2/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU=
291
-github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
292
-github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
293 230
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
294 231
 github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
295 232
 github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
296
-github.com/rs/zerolog v1.22.0 h1:XrVUjV4K+izZpKXZHlPrYQiDtmdGiCylnT4i43AAWxg=
297
-github.com/rs/zerolog v1.22.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM=
298
-github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
299
-github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
300
-github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
301
-github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
233
+github.com/rs/zerolog v1.23.0 h1:UskrK+saS9P9Y789yNNulYKdARjPZuS35B8gJF2x60g=
234
+github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo=
302 235
 github.com/sebdah/goldie/v2 v2.5.3/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI=
303 236
 github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
304 237
 github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
305
-github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
306 238
 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
307 239
 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
308 240
 github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
309
-github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
310
-github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
311 241
 github.com/smira/go-statsd v1.3.2 h1:1EeuzxNZ/TD9apbTOFSM9nulqfcsQFmT4u1A2DREabI=
312 242
 github.com/smira/go-statsd v1.3.2/go.mod h1:1srXJ9/pbnN04G8f4F1jUzsGOnwkPKXciyqpewGlkC4=
313
-github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
314
-github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
315
-github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
316
-github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
317
-github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
318
-github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
319
-github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
320 243
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
321 244
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
322 245
 github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
@@ -329,148 +252,214 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
329 252
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
330 253
 github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
331 254
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
332
-github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
333 255
 github.com/tylertreat/BoomFilters v0.0.0-20210315201527-1a82519a3e43 h1:QEePdg0ty2r0t1+qwfZmQ4OOl/MB2UXIeJSpIZv56lg=
334 256
 github.com/tylertreat/BoomFilters v0.0.0-20210315201527-1a82519a3e43/go.mod h1:OYRfF6eb5wY9VRFkXJH8FFBi3plw2v+giaIu7P054pM=
335
-github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
336
-github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
337
-github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
338
-github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
339
-github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
340
-github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
341
-github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
342
-github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
343
-github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
257
+github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
258
+github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
344 259
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
345 260
 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
346
-go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
347
-go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
348
-go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
349
-go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
261
+go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
262
+go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
350 263
 go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
351
-go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
352
-go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
264
+go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
265
+go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
353 266
 go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
354 267
 go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
355 268
 go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
356
-go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
357
-go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
358 269
 go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
359 270
 go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
360 271
 go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
361 272
 go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg=
362 273
 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
363
-go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
364
-go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
365 274
 go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
366 275
 go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
367 276
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
368
-golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
369 277
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
370 278
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
371
-golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
279
+golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
372 280
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
373 281
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
374
-golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
375
-golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
282
+golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
283
+golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
376 284
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
285
+golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
286
+golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
287
+golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
288
+golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
289
+golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
290
+golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
291
+golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
292
+golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
293
+golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
294
+golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
295
+golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
377 296
 golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
378 297
 golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
379 298
 golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
380 299
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
381
-golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
300
+golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
301
+golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
382 302
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
303
+golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
304
+golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
305
+golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
306
+golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
307
+golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
308
+golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
383 309
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
310
+golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
384 311
 golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
312
+golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
313
+golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
385 314
 golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
386 315
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
387 316
 golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
388 317
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
389 318
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
390
-golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
391
-golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
392 319
 golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
393
-golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
394
-golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
395 320
 golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
396
-golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
397 321
 golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
398 322
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
399 323
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
324
+golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
325
+golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
400 326
 golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
401 327
 golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
402 328
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
403
-golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
329
+golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
330
+golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
331
+golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
332
+golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
404 333
 golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
334
+golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
335
+golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
336
+golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
337
+golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
338
+golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
339
+golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
340
+golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
341
+golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
405 342
 golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
343
+golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
344
+golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
406 345
 golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
407 346
 golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
408
-golang.org/x/net v0.0.0-20210510120150-4163338589ed h1:p9UgmWI9wKpfYmgaV/IZKGdXc5qEK45tDwwwDyjS26I=
409
-golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
347
+golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
348
+golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 h1:4CSI6oo7cOjJKajidEljs9h+uP0rRZBPPPhcCbj5mw8=
349
+golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
410 350
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
411 351
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
352
+golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
353
+golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
354
+golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
355
+golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
412 356
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
413 357
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
414 358
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
415 359
 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
416 360
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
417 361
 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
362
+golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
418 363
 golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
419 364
 golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
420 365
 golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
421 366
 golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
422
-golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
423 367
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
424 368
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
425
-golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
426
-golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
427
-golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
428 369
 golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
429
-golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
430 370
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
431 371
 golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
432 372
 golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
373
+golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
433 374
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
434 375
 golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
435 376
 golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
377
+golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
378
+golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
379
+golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
436 380
 golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
437 381
 golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
438
-golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
439
-golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
382
+golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
383
+golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
384
+golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
440 385
 golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
386
+golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
387
+golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
388
+golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
389
+golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
390
+golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
391
+golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
441 392
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
393
+golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
394
+golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
395
+golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
396
+golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
397
+golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
442 398
 golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
443 399
 golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
400
+golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
444 401
 golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
445 402
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
446 403
 golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
447 404
 golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
448
-golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
449 405
 golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
450
-golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E=
451
-golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
406
+golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
407
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
408
+golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
409
+golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
452 410
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
411
+golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
453 412
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
413
+golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
454 414
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
455 415
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
456 416
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
457
-golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
417
+golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
418
+golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
458 419
 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
459
-golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
460
-golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
461 420
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
462 421
 golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
463 422
 golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
464 423
 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
424
+golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
465 425
 golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
466
-golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
426
+golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
427
+golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
467 428
 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
429
+golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
468 430
 golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
431
+golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
432
+golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
433
+golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
434
+golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
469 435
 golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
470 436
 golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
437
+golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
438
+golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
471 439
 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
472
-golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
440
+golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
441
+golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
442
+golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
443
+golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
444
+golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
445
+golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
446
+golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
447
+golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
448
+golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
449
+golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
450
+golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
451
+golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
452
+golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
453
+golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
454
+golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
455
+golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
456
+golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
457
+golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
458
+golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
459
+golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
460
+golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
473 461
 golang.org/x/tools v0.0.0-20200820010801-b793a1359eac/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
462
+golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
474 463
 golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
475 464
 golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
476 465
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -478,59 +467,108 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
478 467
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
479 468
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
480 469
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
481
-google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
470
+google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
471
+google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
472
+google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
473
+google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
474
+google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
475
+google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
476
+google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
477
+google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
478
+google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
479
+google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
480
+google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
481
+google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
482
+google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
483
+google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
484
+google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM=
485
+google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc=
482 486
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
483
-google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
484 487
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
488
+google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
489
+google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
490
+google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
491
+google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
485 492
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
486 493
 google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
494
+google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
487 495
 google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
488
-google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
496
+google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
497
+google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
489 498
 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
490
-google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
499
+google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
500
+google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
501
+google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
502
+google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
503
+google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
504
+google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
505
+google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
506
+google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA=
507
+google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
508
+google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
509
+google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
510
+google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
511
+google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
512
+google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
513
+google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
514
+google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
515
+google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U=
516
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
517
+google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
518
+google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
519
+google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
520
+google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
491 521
 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
492
-google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
493 522
 google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
494
-google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
495
-google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
523
+google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
496 524
 google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
497
-google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
525
+google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
498 526
 google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
527
+google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
528
+google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
529
+google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
530
+google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
531
+google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
532
+google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
499 533
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
500 534
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
501 535
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
502 536
 google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
503 537
 google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
538
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
504 539
 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
540
+google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
541
+google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
542
+google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
505 543
 google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
506
-google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
507 544
 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
545
+google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
546
+google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
508 547
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
509 548
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
510 549
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
511 550
 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
512 551
 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
513
-gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
514 552
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
515
-gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
516
-gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
517
-gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
518
-gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
519
-gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
520
-gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
521 553
 gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
522 554
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
523 555
 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
524 556
 gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
525 557
 gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
526
-gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
527 558
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
528
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
559
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
560
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
529 561
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
530
-honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
562
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
563
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
531 564
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
565
+honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
566
+honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
532 567
 honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
533
-honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
534 568
 honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
535
-sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
536
-sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
569
+honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
570
+honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
571
+honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
572
+rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
573
+rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
574
+rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

+ 36
- 45
internal/cli/access.go Zobrazit soubor

@@ -12,6 +12,10 @@ import (
12 12
 	"strconv"
13 13
 	"strings"
14 14
 	"sync"
15
+
16
+	"github.com/9seconds/mtg/v2/internal/config"
17
+	"github.com/9seconds/mtg/v2/internal/utils"
18
+	"github.com/9seconds/mtg/v2/mtglib"
15 19
 )
16 20
 
17 21
 type accessResponse struct {
@@ -26,33 +30,34 @@ type accessResponse struct {
26 30
 type accessResponseURLs struct {
27 31
 	IP        net.IP `json:"ip"`
28 32
 	Port      uint   `json:"port"`
29
-	TgURL     string `json:"tg_url"`
30
-	TgQrCode  string `json:"tg_qrcode"`
31
-	TmeURL    string `json:"tme_url"`
32
-	TmeQrCode string `json:"tme_qrcode"`
33
+	TgURL     string `json:"tg_url"`     // nolint: tagliatelle
34
+	TgQrCode  string `json:"tg_qrcode"`  // nolint: tagliatelle
35
+	TmeURL    string `json:"tme_url"`    // nolint: tagliatelle
36
+	TmeQrCode string `json:"tme_qrcode"` // nolint: tagliatelle
33 37
 }
34 38
 
35 39
 type Access struct {
36
-	base
37
-
40
+	ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"`                 // nolint: lll
38 41
 	PublicIPv4 net.IP `kong:"help='Public IPv4 address for proxy. By default it is resolved via remote website',name='ipv4',short='i'"`   // nolint: lll
39 42
 	PublicIPv6 net.IP `kong:"help='Public IPv6 address for proxy. By default it is resolved via remote website',name='ipv6',short='I'"`   // nolint: lll
40 43
 	Port       uint   `kong:"help='Port number. Default port is taken from configuration file, bind-to parameter',type:'uint',short='p'"` // nolint: lll
41 44
 	Hex        bool   `kong:"help='Print secret in hex encoding.',short='x'"`
42 45
 }
43 46
 
44
-func (c *Access) Run(cli *CLI, version string) error {
45
-	if err := c.ReadConfig(version); err != nil {
47
+func (a *Access) Run(cli *CLI, version string) error {
48
+	conf, err := utils.ReadConfig(a.ConfigPath)
49
+	if err != nil {
46 50
 		return fmt.Errorf("cannot init config: %w", err)
47 51
 	}
48 52
 
49
-	return c.Execute(cli)
50
-}
51
-
52
-func (c *Access) Execute(cli *CLI) error {
53 53
 	resp := &accessResponse{}
54
-	resp.Secret.Base64 = c.Config.Secret.Base64()
55
-	resp.Secret.Hex = c.Config.Secret.Hex()
54
+	resp.Secret.Base64 = conf.Secret.Base64()
55
+	resp.Secret.Hex = conf.Secret.Hex()
56
+
57
+	ntw, err := makeNetwork(conf, version)
58
+	if err != nil {
59
+		return fmt.Errorf("cannot init network: %w", err)
60
+	}
56 61
 
57 62
 	wg := &sync.WaitGroup{}
58 63
 	wg.Add(2) // nolint: gomnd
@@ -60,31 +65,31 @@ func (c *Access) Execute(cli *CLI) error {
60 65
 	go func() {
61 66
 		defer wg.Done()
62 67
 
63
-		ip := cli.Access.PublicIPv4
68
+		ip := a.PublicIPv4
64 69
 		if ip == nil {
65
-			ip = c.getIP("tcp4")
70
+			ip = a.getIP(ntw, "tcp4")
66 71
 		}
67 72
 
68 73
 		if ip != nil {
69 74
 			ip = ip.To4()
70 75
 		}
71 76
 
72
-		resp.IPv4 = c.makeURLs(ip, cli)
77
+		resp.IPv4 = a.makeURLs(conf, ip)
73 78
 	}()
74 79
 
75 80
 	go func() {
76 81
 		defer wg.Done()
77 82
 
78
-		ip := cli.Access.PublicIPv6
83
+		ip := a.PublicIPv6
79 84
 		if ip == nil {
80
-			ip = c.getIP("tcp6")
85
+			ip = a.getIP(ntw, "tcp6")
81 86
 		}
82 87
 
83 88
 		if ip != nil {
84 89
 			ip = ip.To16()
85 90
 		}
86 91
 
87
-		resp.IPv6 = c.makeURLs(ip, cli)
92
+		resp.IPv6 = a.makeURLs(conf, ip)
88 93
 	}()
89 94
 
90 95
 	wg.Wait()
@@ -100,9 +105,9 @@ func (c *Access) Execute(cli *CLI) error {
100 105
 	return nil
101 106
 }
102 107
 
103
-func (c *Access) getIP(protocol string) net.IP {
104
-	client := c.Network.MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error) {
105
-		return c.Network.DialContext(ctx, protocol, address) // nolint: wrapcheck
108
+func (a *Access) getIP(ntw mtglib.Network, protocol string) net.IP {
109
+	client := ntw.MakeHTTPClient(func(ctx context.Context, network, address string) (net.Conn, error) {
110
+		return ntw.DialContext(ctx, protocol, address) // nolint: wrapcheck
106 111
 	})
107 112
 
108 113
 	req, err := http.NewRequest(http.MethodGet, "https://ifconfig.co", nil) // nolint: noctx
@@ -134,24 +139,24 @@ func (c *Access) getIP(protocol string) net.IP {
134 139
 	return net.ParseIP(strings.TrimSpace(string(data)))
135 140
 }
136 141
 
137
-func (c *Access) makeURLs(ip net.IP, cli *CLI) *accessResponseURLs {
142
+func (a *Access) makeURLs(conf *config.Config, ip net.IP) *accessResponseURLs {
138 143
 	if ip == nil {
139 144
 		return nil
140 145
 	}
141 146
 
142
-	portNo := cli.Access.Port
147
+	portNo := a.Port
143 148
 	if portNo == 0 {
144
-		portNo = c.Config.BindTo.PortValue(0)
149
+		portNo = conf.BindTo.Port
145 150
 	}
146 151
 
147 152
 	values := url.Values{}
148 153
 	values.Set("server", ip.String())
149 154
 	values.Set("port", strconv.Itoa(int(portNo)))
150 155
 
151
-	if cli.Access.Hex {
152
-		values.Set("secret", c.Config.Secret.Hex())
156
+	if a.Hex {
157
+		values.Set("secret", conf.Secret.Hex())
153 158
 	} else {
154
-		values.Set("secret", c.Config.Secret.Base64())
159
+		values.Set("secret", conf.Secret.Base64())
155 160
 	}
156 161
 
157 162
 	urlQuery := values.Encode()
@@ -171,22 +176,8 @@ func (c *Access) makeURLs(ip net.IP, cli *CLI) *accessResponseURLs {
171 176
 			RawQuery: urlQuery,
172 177
 		}).String(),
173 178
 	}
174
-	rv.TgQrCode = c.makeQRCode(rv.TgURL)
175
-	rv.TmeQrCode = c.makeQRCode(rv.TmeURL)
179
+	rv.TgQrCode = utils.MakeQRCodeURL(rv.TgURL)
180
+	rv.TmeQrCode = utils.MakeQRCodeURL(rv.TmeURL)
176 181
 
177 182
 	return rv
178 183
 }
179
-
180
-func (c *Access) makeQRCode(data string) string {
181
-	values := url.Values{}
182
-	values.Set("qzone", "4")
183
-	values.Set("format", "svg")
184
-	values.Set("data", data)
185
-
186
-	return (&url.URL{
187
-		Scheme:   "https",
188
-		Host:     "api.qrserver.com",
189
-		Path:     "v1/create-qr-code",
190
-		RawQuery: values.Encode(),
191
-	}).String()
192
-}

+ 0
- 197
internal/cli/access_test.go Zobrazit soubor

@@ -1,197 +0,0 @@
1
-package cli_test
2
-
3
-import (
4
-	"net"
5
-	"net/http"
6
-	"testing"
7
-
8
-	"github.com/9seconds/mtg/v2/internal/config"
9
-	"github.com/9seconds/mtg/v2/internal/testlib"
10
-	"github.com/9seconds/mtg/v2/mtglib"
11
-	"github.com/jarcoal/httpmock"
12
-	"github.com/stretchr/testify/suite"
13
-	"github.com/xeipuuv/gojsonschema"
14
-)
15
-
16
-var accressResponseJSONSchema = func() *gojsonschema.Schema {
17
-	schema, err := gojsonschema.NewSchema(gojsonschema.NewStringLoader(`
18
-{
19
-    "type": "object",
20
-    "required": ["secret"],
21
-    "additionalProperties": true,
22
-    "properties": {
23
-        "secret": {
24
-            "type": "object",
25
-            "required": [
26
-                "hex",
27
-                "base64"
28
-            ],
29
-            "additionalProperties": false,
30
-            "properties": {
31
-                "hex": {
32
-                    "type": "string",
33
-                    "minLength": 34
34
-                },
35
-                "base64": {
36
-                    "type": "string",
37
-                    "minLength": 10
38
-                }
39
-            }
40
-        },
41
-        "ipv4": {
42
-            "$ref": "#/definitions/ip"
43
-        },
44
-        "ipv6": {
45
-            "$ref": "#/definitions/ip"
46
-        }
47
-    },
48
-    "definitions": {
49
-        "ip": {
50
-            "type": "object",
51
-            "required": [
52
-                "ip",
53
-                "port",
54
-                "tg_url",
55
-                "tg_qrcode",
56
-                "tme_url",
57
-                "tme_qrcode"
58
-            ],
59
-            "additionalProperties": false,
60
-            "properties": {
61
-                "ip": {
62
-                    "type": "string",
63
-                    "minLength": 1,
64
-                    "anyOf": [
65
-                        {
66
-                            "format": "ipv4"
67
-                        },
68
-                        {
69
-                            "format": "ipv6"
70
-                        }
71
-                    ]
72
-                },
73
-                "port": {
74
-                    "type": "integer",
75
-                    "multipleOf": 1.0,
76
-                    "exclusiveMinimum": 0,
77
-                    "exclusiveMaximum": 65536
78
-                },
79
-                "tg_url": {
80
-                    "type": "string",
81
-                    "minLength": 1,
82
-                    "format": "uri"
83
-                },
84
-                "tg_qrcode": {
85
-                    "type": "string",
86
-                    "minLength": 1,
87
-                    "format": "uri"
88
-                },
89
-                "tme_url": {
90
-                    "type": "string",
91
-                    "minLength": 1,
92
-                    "format": "uri"
93
-                },
94
-                "tme_qrcode": {
95
-                    "type": "string",
96
-                    "minLength": 1,
97
-                    "format": "uri"
98
-                }
99
-            }
100
-        }
101
-    }
102
-}
103
-    `))
104
-	if err != nil {
105
-		panic(err)
106
-	}
107
-
108
-	return schema
109
-}()
110
-
111
-type AccessTestSuite struct {
112
-	CommonTestSuite
113
-}
114
-
115
-func (suite *AccessTestSuite) SetupTest() {
116
-	suite.CommonTestSuite.SetupTest()
117
-
118
-	suite.cli.Access.Config = &config.Config{}
119
-	suite.cli.Access.Config.Secret = mtglib.GenerateSecret("google.com")
120
-	suite.cli.Access.Network = suite.networkMock
121
-
122
-	suite.NoError(
123
-		suite.cli.Access.Config.BindTo.UnmarshalText([]byte("0.0.0.0:80")))
124
-}
125
-
126
-func (suite *AccessTestSuite) TestGenerateNoCalls() {
127
-	suite.cli.Access.PublicIPv4 = net.ParseIP("10.0.0.10")
128
-	suite.cli.Access.PublicIPv6 = net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
129
-
130
-	output := testlib.CaptureStdout(func() {
131
-		suite.NoError(suite.cli.Access.Execute(suite.cli))
132
-	})
133
-
134
-	validated, err := accressResponseJSONSchema.Validate(
135
-		gojsonschema.NewStringLoader(output))
136
-	suite.NoError(err)
137
-	suite.Empty(validated.Errors())
138
-	suite.True(validated.Valid())
139
-
140
-	suite.Contains(output, "10.0.0.10")
141
-	suite.Contains(output, "2001:db8:85a3::8a2e:370:7334")
142
-	suite.Contains(output, "ipv4")
143
-	suite.Contains(output, "ipv6")
144
-	suite.Contains(output, suite.cli.Access.Config.Secret.Base64())
145
-	suite.Contains(output, suite.cli.Access.Config.Secret.Hex())
146
-}
147
-
148
-func (suite *AccessTestSuite) TestGenerateIPv4Call() {
149
-	suite.cli.Access.PublicIPv6 = net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
150
-
151
-	httpmock.RegisterResponder(http.MethodGet, "https://ifconfig.co",
152
-		httpmock.NewStringResponder(http.StatusOK, "10.11.12.13"))
153
-
154
-	output := testlib.CaptureStdout(func() {
155
-		suite.NoError(suite.cli.Access.Execute(suite.cli))
156
-	})
157
-
158
-	validated, err := accressResponseJSONSchema.Validate(
159
-		gojsonschema.NewStringLoader(output))
160
-	suite.NoError(err)
161
-	suite.Empty(validated.Errors())
162
-	suite.True(validated.Valid())
163
-
164
-	suite.Contains(output, "10.11.12.13")
165
-	suite.Contains(output, "2001:db8:85a3::8a2e:370:7334")
166
-	suite.Contains(output, "ipv4")
167
-	suite.Contains(output, "ipv6")
168
-	suite.Contains(output, suite.cli.Access.Config.Secret.Base64())
169
-	suite.Contains(output, suite.cli.Access.Config.Secret.Hex())
170
-}
171
-
172
-func (suite *AccessTestSuite) TestIPv4CallFail() {
173
-	suite.cli.Access.PublicIPv6 = net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
174
-
175
-	httpmock.RegisterResponder(http.MethodGet, "https://ifconfig.co",
176
-		httpmock.NewStringResponder(http.StatusForbidden, ""))
177
-
178
-	output := testlib.CaptureStdout(func() {
179
-		suite.NoError(suite.cli.Access.Execute(suite.cli))
180
-	})
181
-
182
-	validated, err := accressResponseJSONSchema.Validate(
183
-		gojsonschema.NewStringLoader(output))
184
-	suite.NoError(err)
185
-	suite.Empty(validated.Errors())
186
-	suite.True(validated.Valid())
187
-
188
-	suite.Contains(output, "2001:db8:85a3::8a2e:370:7334")
189
-	suite.NotContains(output, "ipv4")
190
-	suite.Contains(output, "ipv6")
191
-	suite.Contains(output, suite.cli.Access.Config.Secret.Base64())
192
-	suite.Contains(output, suite.cli.Access.Config.Secret.Hex())
193
-}
194
-
195
-func TestAccess(t *testing.T) { // nolint: paralleltest
196
-	suite.Run(t, &AccessTestSuite{})
197
-}

+ 0
- 81
internal/cli/base.go Zobrazit soubor

@@ -1,81 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"fmt"
5
-	"net"
6
-	"net/url"
7
-	"os"
8
-
9
-	"github.com/9seconds/mtg/v2/internal/config"
10
-	"github.com/9seconds/mtg/v2/mtglib"
11
-	"github.com/9seconds/mtg/v2/network"
12
-)
13
-
14
-type base struct {
15
-	ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
16
-
17
-	Network mtglib.Network `kong:"-"`
18
-	Config  *config.Config `kong:"-"`
19
-}
20
-
21
-func (b *base) ReadConfig(version string) error {
22
-	content, err := os.ReadFile(b.ConfigPath)
23
-	if err != nil {
24
-		return fmt.Errorf("cannot read config file: %w", err)
25
-	}
26
-
27
-	conf, err := config.Parse(content)
28
-	if err != nil {
29
-		return fmt.Errorf("cannot parse config: %w", err)
30
-	}
31
-
32
-	ntw, err := b.makeNetwork(conf, version)
33
-	if err != nil {
34
-		return fmt.Errorf("cannot build a network: %w", err)
35
-	}
36
-
37
-	b.Config = conf
38
-	b.Network = ntw
39
-
40
-	return nil
41
-}
42
-
43
-func (b *base) makeNetwork(conf *config.Config, version string) (mtglib.Network, error) {
44
-	tcpTimeout := conf.Network.Timeout.TCP.Value(network.DefaultTimeout)
45
-	httpTimeout := conf.Network.Timeout.HTTP.Value(network.DefaultHTTPTimeout)
46
-	dohIP := conf.Network.DOHIP.Value(net.ParseIP(network.DefaultDOHHostname)).String()
47
-	bufferSize := conf.TCPBuffer.Value(network.DefaultBufferSize)
48
-	userAgent := "mtg/" + version
49
-
50
-	baseDialer, err := network.NewDefaultDialer(tcpTimeout, int(bufferSize))
51
-	if err != nil {
52
-		return nil, fmt.Errorf("cannot build a default dialer: %w", err)
53
-	}
54
-
55
-	proxyURLs := make([]*url.URL, 0, len(conf.Network.Proxies))
56
-
57
-	for _, v := range conf.Network.Proxies {
58
-		if value := v.Value(nil); value != nil {
59
-			proxyURLs = append(proxyURLs, v.Value(nil))
60
-		}
61
-	}
62
-
63
-	switch len(proxyURLs) {
64
-	case 0:
65
-		return network.NewNetwork(baseDialer, userAgent, dohIP, httpTimeout) // nolint: wrapcheck
66
-	case 1:
67
-		socksDialer, err := network.NewSocks5Dialer(baseDialer, proxyURLs[0])
68
-		if err != nil {
69
-			return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
70
-		}
71
-
72
-		return network.NewNetwork(socksDialer, userAgent, dohIP, httpTimeout) // nolint: wrapcheck
73
-	}
74
-
75
-	socksDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, proxyURLs)
76
-	if err != nil {
77
-		return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
78
-	}
79
-
80
-	return network.NewNetwork(socksDialer, userAgent, dohIP, httpTimeout) // nolint: wrapcheck
81
-}

+ 0
- 33
internal/cli/base_internal_test.go Zobrazit soubor

@@ -1,33 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"path/filepath"
5
-	"testing"
6
-
7
-	"github.com/stretchr/testify/suite"
8
-)
9
-
10
-type BaseTestSuite struct {
11
-	suite.Suite
12
-
13
-	b base
14
-}
15
-
16
-func (suite *BaseTestSuite) SetupTest() {
17
-	suite.b = base{}
18
-}
19
-
20
-func (suite *BaseTestSuite) TestReadConfigNok() {
21
-	suite.b.ConfigPath = filepath.Join("testdata", "unknown")
22
-	suite.Error(suite.b.ReadConfig("dev"))
23
-}
24
-
25
-func (suite *BaseTestSuite) TestReadConfig() {
26
-	suite.b.ConfigPath = filepath.Join("testdata", "minimal.toml")
27
-	suite.NoError(suite.b.ReadConfig("dev"))
28
-}
29
-
30
-func TestBase(t *testing.T) {
31
-	t.Parallel()
32
-	suite.Run(t, &BaseTestSuite{})
33
-}

+ 2
- 1
internal/cli/cli.go Zobrazit soubor

@@ -5,6 +5,7 @@ import "github.com/alecthomas/kong"
5 5
 type CLI struct {
6 6
 	GenerateSecret GenerateSecret   `kong:"cmd,help='Generate new proxy secret'"`
7 7
 	Access         Access           `kong:"cmd,help='Print access information.'"`
8
-	Run            Proxy            `kong:"cmd,help='Run proxy.'"`
8
+	Run            Run              `kong:"cmd,help='Run proxy.'"`
9
+	SimpleRun      SimpleRun        `kong:"cmd,help='Run proxy without config file.'"`
9 10
 	Version        kong.VersionFlag `kong:"help='Print version.',short='v'"`
10 11
 }

+ 2
- 2
internal/cli/generate_secret.go Zobrazit soubor

@@ -11,10 +11,10 @@ type GenerateSecret struct {
11 11
 	Hex      bool   `kong:"help='Print secret in hex encoding.',short='x'"`
12 12
 }
13 13
 
14
-func (c *GenerateSecret) Run(cli *CLI, _ string) error {
14
+func (g *GenerateSecret) Run(cli *CLI, _ string) error {
15 15
 	secret := mtglib.GenerateSecret(cli.GenerateSecret.HostName)
16 16
 
17
-	if cli.GenerateSecret.Hex {
17
+	if g.Hex {
18 18
 		fmt.Println(secret.Hex()) // nolint: forbidigo
19 19
 	} else {
20 20
 		fmt.Println(secret.Base64()) // nolint: forbidigo

+ 0
- 51
internal/cli/generate_secret_test.go Zobrazit soubor

@@ -1,51 +0,0 @@
1
-package cli_test
2
-
3
-import (
4
-	"strings"
5
-	"testing"
6
-
7
-	"github.com/9seconds/mtg/v2/internal/testlib"
8
-	"github.com/9seconds/mtg/v2/mtglib"
9
-	"github.com/stretchr/testify/suite"
10
-)
11
-
12
-type GenerateSecretTestSuite struct {
13
-	CommonTestSuite
14
-}
15
-
16
-func (suite *GenerateSecretTestSuite) SetupTest() {
17
-	suite.CommonTestSuite.SetupTest()
18
-
19
-	suite.cli.GenerateSecret.HostName = "google.com"
20
-}
21
-
22
-func (suite *GenerateSecretTestSuite) TestDefault() {
23
-	output := testlib.CaptureStdout(func() {
24
-		suite.NoError(suite.cli.GenerateSecret.Run(suite.cli, "dev"))
25
-	})
26
-	suite.True(strings.HasPrefix(output, "7"))
27
-
28
-	secret, err := mtglib.ParseSecret(output)
29
-	suite.NoError(err)
30
-	suite.True(secret.Valid())
31
-	suite.Equal("google.com", secret.Host)
32
-}
33
-
34
-func (suite *GenerateSecretTestSuite) TestHex() {
35
-	suite.cli.GenerateSecret.Hex = true
36
-
37
-	output := testlib.CaptureStdout(func() {
38
-		suite.NoError(suite.cli.GenerateSecret.Run(suite.cli, "dev"))
39
-	})
40
-	suite.True(strings.HasPrefix(output, "ee"))
41
-
42
-	secret, err := mtglib.ParseSecret(output)
43
-	suite.NoError(err)
44
-	suite.True(secret.Valid())
45
-	suite.Equal("google.com", secret.Host)
46
-}
47
-
48
-func TestGenerateSecret(t *testing.T) {
49
-	t.Parallel()
50
-	suite.Run(t, &GenerateSecretTestSuite{})
51
-}

+ 0
- 37
internal/cli/init_test.go Zobrazit soubor

@@ -1,37 +0,0 @@
1
-package cli_test
2
-
3
-import (
4
-	"net/http"
5
-
6
-	"github.com/9seconds/mtg/v2/internal/cli"
7
-	"github.com/9seconds/mtg/v2/internal/testlib"
8
-	"github.com/jarcoal/httpmock"
9
-	"github.com/stretchr/testify/mock"
10
-	"github.com/stretchr/testify/suite"
11
-)
12
-
13
-type CommonTestSuite struct {
14
-	suite.Suite
15
-
16
-	cli         *cli.CLI
17
-	networkMock *testlib.MtglibNetworkMock
18
-	httpClient  *http.Client
19
-}
20
-
21
-func (suite *CommonTestSuite) SetupTest() {
22
-	suite.networkMock = &testlib.MtglibNetworkMock{}
23
-	suite.httpClient = &http.Client{}
24
-	suite.cli = &cli.CLI{}
25
-
26
-	httpmock.ActivateNonDefault(suite.httpClient)
27
-
28
-	suite.networkMock.
29
-		On("MakeHTTPClient", mock.Anything).
30
-		Maybe().
31
-		Return(suite.httpClient)
32
-}
33
-
34
-func (suite *CommonTestSuite) TearDownTest() {
35
-	suite.networkMock.AssertExpectations(suite.T())
36
-	httpmock.DeactivateAndReset()
37
-}

+ 0
- 167
internal/cli/proxy.go Zobrazit soubor

@@ -1,167 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"fmt"
5
-	"net"
6
-	"os"
7
-
8
-	"github.com/9seconds/mtg/v2/antireplay"
9
-	"github.com/9seconds/mtg/v2/events"
10
-	"github.com/9seconds/mtg/v2/internal/utils"
11
-	"github.com/9seconds/mtg/v2/ipblocklist"
12
-	"github.com/9seconds/mtg/v2/logger"
13
-	"github.com/9seconds/mtg/v2/mtglib"
14
-	"github.com/9seconds/mtg/v2/stats"
15
-	"github.com/rs/zerolog"
16
-)
17
-
18
-type Proxy struct {
19
-	base
20
-}
21
-
22
-func (c *Proxy) Run(cli *CLI, version string) error {
23
-	if err := c.ReadConfig(version); err != nil {
24
-		return fmt.Errorf("cannot init config: %w", err)
25
-	}
26
-
27
-	return c.Execute()
28
-}
29
-
30
-func (c *Proxy) Execute() error {
31
-	zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
32
-	zerolog.TimestampFieldName = "timestamp"
33
-	zerolog.LevelFieldName = "level"
34
-
35
-	if c.Config.Debug {
36
-		zerolog.SetGlobalLevel(zerolog.DebugLevel)
37
-	} else {
38
-		zerolog.SetGlobalLevel(zerolog.WarnLevel)
39
-	}
40
-
41
-	ctx := utils.RootContext()
42
-	opts := mtglib.ProxyOpts{
43
-		Logger:          logger.NewZeroLogger(zerolog.New(os.Stdout).With().Timestamp().Logger()),
44
-		Network:         c.Network,
45
-		AntiReplayCache: antireplay.NewNoop(),
46
-		IPBlocklist:     ipblocklist.NewNoop(),
47
-		EventStream:     events.NewNoopStream(),
48
-
49
-		Secret:             c.Config.Secret,
50
-		BufferSize:         c.Config.TCPBuffer.Value(mtglib.DefaultBufferSize),
51
-		DomainFrontingPort: c.Config.DomainFrontingPort.Value(mtglib.DefaultDomainFrontingPort),
52
-		IdleTimeout:        c.Config.Network.Timeout.Idle.Value(mtglib.DefaultIdleTimeout),
53
-		PreferIP:           c.Config.PreferIP.Value(mtglib.DefaultPreferIP),
54
-	}
55
-
56
-	opts.Logger.BindStr("configuration", c.Config.String()).Debug("configuration")
57
-
58
-	c.setupAntiReplayCache(&opts)
59
-
60
-	if err := c.setupIPBlocklist(&opts); err != nil {
61
-		return fmt.Errorf("cannot setup ipblocklist: %w", err)
62
-	}
63
-
64
-	if err := c.setupEventStream(&opts); err != nil {
65
-		return fmt.Errorf("cannot setup event stream: %w", err)
66
-	}
67
-
68
-	proxy, err := mtglib.NewProxy(opts)
69
-	if err != nil {
70
-		return fmt.Errorf("cannot create a proxy: %w", err)
71
-	}
72
-
73
-	listener, err := net.Listen("tcp", c.Config.BindTo.String())
74
-	if err != nil {
75
-		return fmt.Errorf("cannot start proxy: %w", err)
76
-	}
77
-
78
-	go proxy.Serve(listener) // nolint: errcheck
79
-
80
-	<-ctx.Done()
81
-	listener.Close()
82
-	proxy.Shutdown()
83
-
84
-	return nil
85
-}
86
-
87
-func (c *Proxy) setupAntiReplayCache(opts *mtglib.ProxyOpts) {
88
-	if !c.Config.Defense.AntiReplay.Enabled {
89
-		return
90
-	}
91
-
92
-	opts.AntiReplayCache = antireplay.NewStableBloomFilter(
93
-		c.Config.Defense.AntiReplay.MaxSize.Value(antireplay.DefaultStableBloomFilterMaxSize),
94
-		c.Config.Defense.AntiReplay.ErrorRate.Value(antireplay.DefaultStableBloomFilterErrorRate),
95
-	)
96
-}
97
-
98
-func (c *Proxy) setupIPBlocklist(opts *mtglib.ProxyOpts) error {
99
-	if !c.Config.Defense.Blocklist.Enabled {
100
-		return nil
101
-	}
102
-
103
-	remoteURLs := []string{}
104
-	localFiles := []string{}
105
-
106
-	for _, v := range c.Config.Defense.Blocklist.URLs {
107
-		if v.IsRemote() {
108
-			remoteURLs = append(remoteURLs, v.String())
109
-		} else {
110
-			localFiles = append(localFiles, v.String())
111
-		}
112
-	}
113
-
114
-	firehol, err := ipblocklist.NewFirehol(opts.Logger.Named("ipblockist"),
115
-		c.Network,
116
-		c.Config.Defense.Blocklist.DownloadConcurrency,
117
-		remoteURLs,
118
-		localFiles)
119
-	if err != nil {
120
-		return err // nolint: wrapcheck
121
-	}
122
-
123
-	go firehol.Run(c.Config.Defense.Blocklist.UpdateEach.Value(ipblocklist.DefaultFireholUpdateEach))
124
-
125
-	opts.IPBlocklist = firehol
126
-
127
-	return nil
128
-}
129
-
130
-func (c *Proxy) setupEventStream(opts *mtglib.ProxyOpts) error {
131
-	factories := make([]events.ObserverFactory, 0, 2)
132
-
133
-	if c.Config.Stats.StatsD.Enabled {
134
-		statsdFactory, err := stats.NewStatsd(
135
-			c.Config.Stats.StatsD.Address.String(),
136
-			opts.Logger.Named("statsd"),
137
-			c.Config.Stats.StatsD.MetricPrefix.Value(stats.DefaultStatsdMetricPrefix),
138
-			c.Config.Stats.StatsD.TagFormat.Value(stats.DefaultStatsdTagFormat))
139
-		if err != nil {
140
-			return fmt.Errorf("cannot build statsd observer: %w", err)
141
-		}
142
-
143
-		factories = append(factories, statsdFactory.Make)
144
-	}
145
-
146
-	if c.Config.Stats.Prometheus.Enabled {
147
-		prometheus := stats.NewPrometheus(
148
-			c.Config.Stats.Prometheus.MetricPrefix.Value(stats.DefaultMetricPrefix),
149
-			c.Config.Stats.Prometheus.HTTPPath.Value("/"),
150
-		)
151
-
152
-		listener, err := net.Listen("tcp", c.Config.Stats.Prometheus.BindTo.String())
153
-		if err != nil {
154
-			return fmt.Errorf("cannot start a listener for prometheus: %w", err)
155
-		}
156
-
157
-		go prometheus.Serve(listener) // nolint: errcheck
158
-
159
-		factories = append(factories, prometheus.Make)
160
-	}
161
-
162
-	if len(factories) > 0 {
163
-		opts.EventStream = events.NewEventStream(factories)
164
-	}
165
-
166
-	return nil
167
-}

+ 20
- 0
internal/cli/run.go Zobrazit soubor

@@ -0,0 +1,20 @@
1
+package cli
2
+
3
+import (
4
+	"fmt"
5
+
6
+	"github.com/9seconds/mtg/v2/internal/utils"
7
+)
8
+
9
+type Run struct {
10
+	ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
11
+}
12
+
13
+func (r *Run) Run(cli *CLI, version string) error {
14
+	conf, err := utils.ReadConfig(r.ConfigPath)
15
+	if err != nil {
16
+		return fmt.Errorf("cannot init config: %w", err)
17
+	}
18
+
19
+	return runProxy(conf, version)
20
+}

+ 209
- 0
internal/cli/run_proxy.go Zobrazit soubor

@@ -0,0 +1,209 @@
1
+package cli
2
+
3
+import (
4
+	"fmt"
5
+	"net"
6
+	"net/url"
7
+	"os"
8
+
9
+	"github.com/9seconds/mtg/v2/antireplay"
10
+	"github.com/9seconds/mtg/v2/events"
11
+	"github.com/9seconds/mtg/v2/internal/config"
12
+	"github.com/9seconds/mtg/v2/internal/utils"
13
+	"github.com/9seconds/mtg/v2/ipblocklist"
14
+	"github.com/9seconds/mtg/v2/logger"
15
+	"github.com/9seconds/mtg/v2/mtglib"
16
+	"github.com/9seconds/mtg/v2/network"
17
+	"github.com/9seconds/mtg/v2/stats"
18
+	"github.com/rs/zerolog"
19
+)
20
+
21
+func makeLogger(conf *config.Config) mtglib.Logger {
22
+	zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
23
+	zerolog.TimestampFieldName = "timestamp"
24
+	zerolog.LevelFieldName = "level"
25
+
26
+	if conf.Debug.Get(false) {
27
+		zerolog.SetGlobalLevel(zerolog.DebugLevel)
28
+	} else {
29
+		zerolog.SetGlobalLevel(zerolog.WarnLevel)
30
+	}
31
+
32
+	baseLogger := zerolog.New(os.Stdout).With().Timestamp().Logger()
33
+
34
+	return logger.NewZeroLogger(baseLogger)
35
+}
36
+
37
+func makeNetwork(conf *config.Config, version string) (mtglib.Network, error) {
38
+	tcpTimeout := conf.Network.Timeout.TCP.Get(network.DefaultTimeout)
39
+	httpTimeout := conf.Network.Timeout.HTTP.Get(network.DefaultHTTPTimeout)
40
+	dohIP := conf.Network.DOHIP.Get(net.ParseIP(network.DefaultDOHHostname)).String()
41
+	bufferSize := conf.TCPBuffer.Get(network.DefaultBufferSize)
42
+	userAgent := "mtg/" + version
43
+
44
+	baseDialer, err := network.NewDefaultDialer(tcpTimeout, int(bufferSize))
45
+	if err != nil {
46
+		return nil, fmt.Errorf("cannot build a default dialer: %w", err)
47
+	}
48
+
49
+	if len(conf.Network.Proxies) == 0 {
50
+		return network.NewNetwork(baseDialer, userAgent, dohIP, httpTimeout) // nolint: wrapcheck
51
+	}
52
+
53
+	proxyURLs := make([]*url.URL, 0, len(conf.Network.Proxies))
54
+
55
+	for _, v := range conf.Network.Proxies {
56
+		if value := v.Get(nil); value != nil {
57
+			proxyURLs = append(proxyURLs, value)
58
+		}
59
+	}
60
+
61
+	if len(proxyURLs) == 1 {
62
+		socksDialer, err := network.NewSocks5Dialer(baseDialer, proxyURLs[0])
63
+		if err != nil {
64
+			return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
65
+		}
66
+
67
+		return network.NewNetwork(socksDialer, userAgent, dohIP, httpTimeout) // nolint: wrapcheck
68
+	}
69
+
70
+	socksDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, proxyURLs)
71
+	if err != nil {
72
+		return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
73
+	}
74
+
75
+	return network.NewNetwork(socksDialer, userAgent, dohIP, httpTimeout) // nolint: wrapcheck
76
+}
77
+
78
+func makeAntiReplayCache(conf *config.Config) mtglib.AntiReplayCache {
79
+	if !conf.Defense.AntiReplay.Enabled.Get(false) {
80
+		return antireplay.NewNoop()
81
+	}
82
+
83
+	return antireplay.NewStableBloomFilter(
84
+		conf.Defense.AntiReplay.MaxSize.Get(antireplay.DefaultStableBloomFilterMaxSize),
85
+		conf.Defense.AntiReplay.ErrorRate.Get(antireplay.DefaultStableBloomFilterErrorRate),
86
+	)
87
+}
88
+
89
+func makeIPBlocklist(conf *config.Config, logger mtglib.Logger, ntw mtglib.Network) (mtglib.IPBlocklist, error) {
90
+	if !conf.Defense.Blocklist.Enabled.Get(false) {
91
+		return ipblocklist.NewNoop(), nil
92
+	}
93
+
94
+	remoteURLs := []string{}
95
+	localFiles := []string{}
96
+
97
+	for _, v := range conf.Defense.Blocklist.URLs {
98
+		if v.IsRemote() {
99
+			remoteURLs = append(remoteURLs, v.String())
100
+		} else {
101
+			localFiles = append(localFiles, v.String())
102
+		}
103
+	}
104
+
105
+	firehol, err := ipblocklist.NewFirehol(logger.Named("ipblockist"),
106
+		ntw,
107
+		conf.Defense.Blocklist.DownloadConcurrency.Get(1),
108
+		remoteURLs,
109
+		localFiles)
110
+	if err != nil {
111
+		return nil, fmt.Errorf("incorrect parameters for firehol: %w", err)
112
+	}
113
+
114
+	return firehol, nil
115
+}
116
+
117
+func makeEventStream(conf *config.Config, logger mtglib.Logger) (mtglib.EventStream, error) {
118
+	factories := make([]events.ObserverFactory, 0, 2) // nolint: gomnd
119
+
120
+	if conf.Stats.StatsD.Enabled.Get(false) {
121
+		statsdFactory, err := stats.NewStatsd(
122
+			conf.Stats.StatsD.Address.Get(""),
123
+			logger.Named("statsd"),
124
+			conf.Stats.StatsD.MetricPrefix.Get(stats.DefaultStatsdMetricPrefix),
125
+			conf.Stats.StatsD.TagFormat.Get(stats.DefaultStatsdTagFormat))
126
+		if err != nil {
127
+			return nil, fmt.Errorf("cannot build statsd observer: %w", err)
128
+		}
129
+
130
+		factories = append(factories, statsdFactory.Make)
131
+	}
132
+
133
+	if conf.Stats.Prometheus.Enabled.Get(false) {
134
+		prometheus := stats.NewPrometheus(
135
+			conf.Stats.Prometheus.MetricPrefix.Get(stats.DefaultMetricPrefix),
136
+			conf.Stats.Prometheus.HTTPPath.Get("/"),
137
+		)
138
+
139
+		listener, err := net.Listen("tcp", conf.Stats.Prometheus.BindTo.Get(""))
140
+		if err != nil {
141
+			return nil, fmt.Errorf("cannot start a listener for prometheus: %w", err)
142
+		}
143
+
144
+		go prometheus.Serve(listener) // nolint: errcheck
145
+
146
+		factories = append(factories, prometheus.Make)
147
+	}
148
+
149
+	if len(factories) > 0 {
150
+		return events.NewEventStream(factories), nil
151
+	}
152
+
153
+	return events.NewNoopStream(), nil
154
+}
155
+
156
+func runProxy(conf *config.Config, version string) error {
157
+	logger := makeLogger(conf)
158
+
159
+	logger.BindStr("configuration", conf.String()).Debug("configuration")
160
+
161
+	ntw, err := makeNetwork(conf, version)
162
+	if err != nil {
163
+		return fmt.Errorf("cannot build network: %w", err)
164
+	}
165
+
166
+	blocklist, err := makeIPBlocklist(conf, logger, ntw)
167
+	if err != nil {
168
+		return fmt.Errorf("cannot build ip blocklist: %w", err)
169
+	}
170
+
171
+	eventStream, err := makeEventStream(conf, logger)
172
+	if err != nil {
173
+		return fmt.Errorf("cannot build event stream: %w", err)
174
+	}
175
+
176
+	opts := mtglib.ProxyOpts{
177
+		Logger:          logger,
178
+		Network:         ntw,
179
+		AntiReplayCache: makeAntiReplayCache(conf),
180
+		IPBlocklist:     blocklist,
181
+		EventStream:     eventStream,
182
+
183
+		Secret:             conf.Secret,
184
+		BufferSize:         conf.TCPBuffer.Get(mtglib.DefaultBufferSize),
185
+		DomainFrontingPort: conf.DomainFrontingPort.Get(mtglib.DefaultDomainFrontingPort),
186
+		IdleTimeout:        conf.Network.Timeout.Idle.Get(mtglib.DefaultIdleTimeout),
187
+		PreferIP:           conf.PreferIP.Get(mtglib.DefaultPreferIP),
188
+	}
189
+
190
+	proxy, err := mtglib.NewProxy(opts)
191
+	if err != nil {
192
+		return fmt.Errorf("cannot create a proxy: %w", err)
193
+	}
194
+
195
+	listener, err := net.Listen("tcp", conf.BindTo.Get(""))
196
+	if err != nil {
197
+		return fmt.Errorf("cannot start proxy: %w", err)
198
+	}
199
+
200
+	ctx := utils.RootContext()
201
+
202
+	go proxy.Serve(listener) // nolint: errcheck
203
+
204
+	<-ctx.Done()
205
+	listener.Close()
206
+	proxy.Shutdown()
207
+
208
+	return nil
209
+}

+ 81
- 0
internal/cli/simple_run.go Zobrazit soubor

@@ -0,0 +1,81 @@
1
+package cli
2
+
3
+import (
4
+	"fmt"
5
+	"net"
6
+	"strconv"
7
+	"time"
8
+
9
+	"github.com/9seconds/mtg/v2/internal/config"
10
+)
11
+
12
+type SimpleRun struct {
13
+	BindTo string `kong:"arg,required,name='bind-to',help='A host:port to bind proxy to.'"`
14
+	Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"`
15
+
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
+}
25
+
26
+func (s *SimpleRun) Run(cli *CLI, version string) error { // nolint: cyclop
27
+	conf := &config.Config{}
28
+
29
+	if err := conf.BindTo.Set(s.BindTo); err != nil {
30
+		return fmt.Errorf("incorrect bind-to parameter: %w", err)
31
+	}
32
+
33
+	if err := conf.Secret.Set(s.Secret); err != nil {
34
+		return fmt.Errorf("incorrect secret: %w", err)
35
+	}
36
+
37
+	if err := conf.Concurrency.Set(strconv.FormatUint(s.Concurrency, 10)); err != nil { // nolint: gomnd
38
+		return fmt.Errorf("incorrect concurrency: %w", err)
39
+	}
40
+
41
+	if err := conf.TCPBuffer.Set(s.TCPBuffer); err != nil {
42
+		return fmt.Errorf("incorrect tcp-buffer: %w", err)
43
+	}
44
+
45
+	if err := conf.PreferIP.Set(s.PreferIP); err != nil {
46
+		return fmt.Errorf("incorrect prefer-ip: %w", err)
47
+	}
48
+
49
+	if err := conf.DomainFrontingPort.Set(strconv.FormatUint(s.DomainFrontingPort, 10)); err != nil { // nolint: gomnd
50
+		return fmt.Errorf("incorrect domain-fronting-port: %w", err)
51
+	}
52
+
53
+	if err := conf.Network.DOHIP.Set(s.DOHIP.String()); err != nil {
54
+		return fmt.Errorf("incorrect doh-ip: %w", err)
55
+	}
56
+
57
+	if err := conf.Network.Timeout.TCP.Set(s.Timeout.String()); err != nil {
58
+		return fmt.Errorf("incorrect timeout: %w", err)
59
+	}
60
+
61
+	if err := conf.Network.Timeout.HTTP.Set(s.Timeout.String()); err != nil {
62
+		return fmt.Errorf("incorrect timeout: %w", err)
63
+	}
64
+
65
+	if err := conf.Network.Timeout.Idle.Set(s.Timeout.String()); err != nil {
66
+		return fmt.Errorf("incorrect timeout: %w", err)
67
+	}
68
+
69
+	if err := conf.Defense.AntiReplay.MaxSize.Set(s.AntiReplayCacheSize); err != nil {
70
+		return fmt.Errorf("incorrect antireplay-cache-size: %w", err)
71
+	}
72
+
73
+	conf.Debug.Value = s.Debug
74
+	conf.Defense.AntiReplay.Enabled.Value = true
75
+
76
+	if err := conf.Validate(); err != nil {
77
+		return fmt.Errorf("invalid result configuration: %w", err)
78
+	}
79
+
80
+	return runProxy(conf, version)
81
+}

+ 25
- 101
internal/config/config.go Zobrazit soubor

@@ -6,29 +6,28 @@ import (
6 6
 	"fmt"
7 7
 
8 8
 	"github.com/9seconds/mtg/v2/mtglib"
9
-	"github.com/pelletier/go-toml"
10 9
 )
11 10
 
12 11
 type Config struct {
13
-	Debug                bool          `json:"debug"`
14
-	Secret               mtglib.Secret `json:"secret"`
15
-	BindTo               TypeHostPort  `json:"bind-to"`
16
-	TCPBuffer            TypeBytes     `json:"tcp-buffer"`
17
-	PreferIP             TypePreferIP  `json:"prefer-ip"`
18
-	DomainFrontingPort   TypePort      `json:"domain-fronting-port"`
19
-	TolerateTimeSkewness TypeDuration  `json:"tolerate-time-skewness"`
20
-	Concurrency          uint          `json:"concurrency"`
12
+	Debug                TypeBool        `json:"debug"`
13
+	Secret               mtglib.Secret   `json:"secret"`
14
+	BindTo               TypeHostPort    `json:"bindTo"`
15
+	TCPBuffer            TypeBytes       `json:"tcpBuffer"`
16
+	PreferIP             TypePreferIP    `json:"preferIp"`
17
+	DomainFrontingPort   TypePort        `json:"domainFrontingPort"`
18
+	TolerateTimeSkewness TypeDuration    `json:"tolerateTimeSkewness"`
19
+	Concurrency          TypeConcurrency `json:"concurrency"`
21 20
 	Defense              struct {
22 21
 		AntiReplay struct {
23
-			Enabled   bool          `json:"enabled"`
24
-			MaxSize   TypeBytes     `json:"max-size"`
25
-			ErrorRate TypeErrorRate `json:"error-rate"`
26
-		} `json:"anti-replay"`
22
+			Enabled   TypeBool      `json:"enabled"`
23
+			MaxSize   TypeBytes     `json:"maxSize"`
24
+			ErrorRate TypeErrorRate `json:"errorRate"`
25
+		} `json:"antiReplay"`
27 26
 		Blocklist struct {
28
-			Enabled             bool               `json:"enabled"`
29
-			DownloadConcurrency uint               `json:"download-concurrency"`
27
+			Enabled             TypeBool           `json:"enabled"`
28
+			DownloadConcurrency TypeConcurrency    `json:"downloadConcurrency"`
30 29
 			URLs                []TypeBlocklistURI `json:"urls"`
31
-			UpdateEach          TypeDuration       `json:"update-each"`
30
+			UpdateEach          TypeDuration       `json:"updateEach"`
32 31
 		} `json:"blocklist"`
33 32
 	} `json:"defense"`
34 33
 	Network struct {
@@ -37,21 +36,21 @@ type Config struct {
37 36
 			HTTP TypeDuration `json:"http"`
38 37
 			Idle TypeDuration `json:"idle"`
39 38
 		} `json:"timeout"`
40
-		DOHIP   TypeIP    `json:"doh-ip"`
41
-		Proxies []TypeURL `json:"proxies"`
39
+		DOHIP   TypeIP         `json:"dohIp"`
40
+		Proxies []TypeProxyURL `json:"proxies"`
42 41
 	} `json:"network"`
43 42
 	Stats struct {
44 43
 		StatsD struct {
45
-			Enabled      bool                `json:"enabled"`
44
+			Enabled      TypeBool            `json:"enabled"`
46 45
 			Address      TypeHostPort        `json:"address"`
47
-			MetricPrefix TypeMetricPrefix    `json:"metric-prefix"`
48
-			TagFormat    TypeStatsdTagFormat `json:"tag-format"`
46
+			MetricPrefix TypeMetricPrefix    `json:"metricPrefix"`
47
+			TagFormat    TypeStatsdTagFormat `json:"tagFormat"`
49 48
 		} `json:"statsd"`
50 49
 		Prometheus struct {
51
-			Enabled      bool             `json:"enabled"`
52
-			BindTo       TypeHostPort     `json:"bind-to"`
53
-			HTTPPath     TypeHTTPPath     `json:"http-path"`
54
-			MetricPrefix TypeMetricPrefix `json:"metric-prefix"`
50
+			Enabled      TypeBool         `json:"enabled"`
51
+			BindTo       TypeHostPort     `json:"bindTo"`
52
+			HTTPPath     TypeHTTPPath     `json:"httpPath"`
53
+			MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
55 54
 		} `json:"prometheus"`
56 55
 	} `json:"stats"`
57 56
 }
@@ -61,7 +60,7 @@ func (c *Config) Validate() error {
61 60
 		return fmt.Errorf("invalid secret %s", c.Secret.String())
62 61
 	}
63 62
 
64
-	if len(c.BindTo.HostValue(nil)) == 0 || c.BindTo.PortValue(0) == 0 {
63
+	if c.BindTo.Get("") == "" {
65 64
 		return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
66 65
 	}
67 66
 
@@ -80,78 +79,3 @@ func (c *Config) String() string {
80 79
 
81 80
 	return buf.String()
82 81
 }
83
-
84
-type configRaw struct {
85
-	Debug                bool   `toml:"debug" json:"debug,omitempty"`
86
-	Secret               string `toml:"secret" json:"secret"`
87
-	BindTo               string `toml:"bind-to" json:"bind-to"`
88
-	TCPBuffer            string `toml:"tcp-buffer" json:"tcp-buffer,omitempty"`
89
-	PreferIP             string `toml:"prefer-ip" json:"prefer-ip,omitempty"`
90
-	DomainFrontingPort   uint   `toml:"domain-fronting-port" json:"domain-fronting-port,omitempty"`
91
-	TolerateTimeSkewness string `toml:"tolerate-time-skewness" json:"tolerate-time-skewness,omitempty"`
92
-	Concurrency          uint   `toml:"concurrency" json:"concurrency,omitempty"`
93
-	Defense              struct {
94
-		AntiReplay struct {
95
-			Enabled   bool    `toml:"enabled" json:"enabled,omitempty"`
96
-			MaxSize   string  `toml:"max-size" json:"max-size,omitempty"`
97
-			ErrorRate float64 `toml:"error-rate" json:"error-rate,omitempty"`
98
-		} `toml:"anti-replay" json:"anti-replay,omitempty"`
99
-		Blocklist struct {
100
-			Enabled             bool     `toml:"enabled" json:"enabled,omitempty"`
101
-			DownloadConcurrency uint     `toml:"download-concurrency" json:"download-concurrency,omitempty"`
102
-			URLs                []string `toml:"urls" json:"urls,omitempty"`
103
-			UpdateEach          string   `toml:"update-each" json:"update-each,omitempty"`
104
-		} `toml:"blocklist" json:"blocklist,omitempty"`
105
-	} `toml:"defense" json:"defense,omitempty"`
106
-	Network struct {
107
-		Timeout struct {
108
-			TCP  string `toml:"tcp" json:"tcp,omitempty"`
109
-			HTTP string `toml:"http" json:"http,omitempty"`
110
-			Idle string `toml:"idle" json:"idle,omitempty"`
111
-		} `toml:"timeout" json:"timeout,omitempty"`
112
-		DOHIP   string   `toml:"doh-ip" json:"doh-ip,omitempty"`
113
-		Proxies []string `toml:"proxies" json:"proxies,omitempty"`
114
-	} `toml:"network" json:"network,omitempty"`
115
-	Stats struct {
116
-		StatsD struct {
117
-			Enabled      bool   `toml:"enabled" json:"enabled,omitempty"`
118
-			Address      string `toml:"address" json:"address,omitempty"`
119
-			MetricPrefix string `toml:"metric-prefix" json:"metric-prefix,omitempty"`
120
-			TagFormat    string `toml:"tag-format" json:"tag-format,omitempty"`
121
-		} `toml:"statsd" json:"statsd,omitempty"`
122
-		Prometheus struct {
123
-			Enabled      bool   `toml:"enabled" json:"enabled,omitempty"`
124
-			BindTo       string `toml:"bind-to" json:"bind-to,omitempty"`
125
-			HTTPPath     string `toml:"http-path" json:"http-path,omitempty"`
126
-			MetricPrefix string `toml:"metric-prefix" json:"metric-prefix,omitempty"`
127
-		} `toml:"prometheus" json:"prometheus,omitempty"`
128
-	} `toml:"stats" json:"stats,omitempty"`
129
-}
130
-
131
-func Parse(rawData []byte) (*Config, error) {
132
-	rawConf := &configRaw{}
133
-	jsonBuf := &bytes.Buffer{}
134
-	conf := &Config{}
135
-
136
-	jsonEncoder := json.NewEncoder(jsonBuf)
137
-	jsonEncoder.SetEscapeHTML(false)
138
-	jsonEncoder.SetIndent("", "")
139
-
140
-	if err := toml.Unmarshal(rawData, rawConf); err != nil {
141
-		return nil, fmt.Errorf("cannot parse toml config: %w", err)
142
-	}
143
-
144
-	if err := jsonEncoder.Encode(rawConf); err != nil {
145
-		panic(err)
146
-	}
147
-
148
-	if err := json.NewDecoder(jsonBuf).Decode(conf); err != nil {
149
-		return nil, fmt.Errorf("cannot parse a config: %w", err)
150
-	}
151
-
152
-	if err := conf.Validate(); err != nil {
153
-		return nil, fmt.Errorf("cannot validate config: %w", err)
154
-	}
155
-
156
-	return conf, nil
157
-}

+ 80
- 0
internal/config/parse.go Zobrazit soubor

@@ -0,0 +1,80 @@
1
+package config
2
+
3
+import (
4
+	"bytes"
5
+	"encoding/json"
6
+	"fmt"
7
+
8
+	"github.com/pelletier/go-toml"
9
+)
10
+
11
+type tomlConfig struct {
12
+	Debug                bool   `toml:"debug" json:"debug,omitempty"`
13
+	Secret               string `toml:"secret" json:"secret"`
14
+	BindTo               string `toml:"bind-to" json:"bindTo"`
15
+	TCPBuffer            string `toml:"tcp-buffer" json:"tcpBuffer,omitempty"`
16
+	PreferIP             string `toml:"prefer-ip" json:"preferIp,omitempty"`
17
+	DomainFrontingPort   uint   `toml:"domain-fronting-port" json:"domainFrontingPort,omitempty"`
18
+	TolerateTimeSkewness string `toml:"tolerate-time-skewness" json:"tolerateTimeSkewness,omitempty"`
19
+	Concurrency          uint   `toml:"concurrency" json:"concurrency,omitempty"`
20
+	Defense              struct {
21
+		AntiReplay struct {
22
+			Enabled   bool    `toml:"enabled" json:"enabled,omitempty"`
23
+			MaxSize   string  `toml:"max-size" json:"maxSize,omitempty"`
24
+			ErrorRate float64 `toml:"error-rate" json:"errorRate,omitempty"`
25
+		} `toml:"anti-replay" json:"antiReplay,omitempty"`
26
+		Blocklist struct {
27
+			Enabled             bool     `toml:"enabled" json:"enabled,omitempty"`
28
+			DownloadConcurrency uint     `toml:"download-concurrency" json:"downloadConcurrency,omitempty"`
29
+			URLs                []string `toml:"urls" json:"urls,omitempty"`
30
+			UpdateEach          string   `toml:"update-each" json:"updateEach,omitempty"`
31
+		} `toml:"blocklist" json:"blocklist,omitempty"`
32
+	} `toml:"defense" json:"defense,omitempty"`
33
+	Network struct {
34
+		Timeout struct {
35
+			TCP  string `toml:"tcp" json:"tcp,omitempty"`
36
+			HTTP string `toml:"http" json:"http,omitempty"`
37
+			Idle string `toml:"idle" json:"idle,omitempty"`
38
+		} `toml:"timeout" json:"timeout,omitempty"`
39
+		DOHIP   string   `toml:"doh-ip" json:"dohIp,omitempty"`
40
+		Proxies []string `toml:"proxies" json:"proxies,omitempty"`
41
+	} `toml:"network" json:"network,omitempty"`
42
+	Stats struct {
43
+		StatsD struct {
44
+			Enabled      bool   `toml:"enabled" json:"enabled,omitempty"`
45
+			Address      string `toml:"address" json:"address,omitempty"`
46
+			MetricPrefix string `toml:"metric-prefix" json:"metricPrefix,omitempty"`
47
+			TagFormat    string `toml:"tag-format" json:"tagFormat,omitempty"`
48
+		} `toml:"statsd" json:"statsd,omitempty"`
49
+		Prometheus struct {
50
+			Enabled      bool   `toml:"enabled" json:"enabled,omitempty"`
51
+			BindTo       string `toml:"bind-to" json:"bindTo,omitempty"`
52
+			HTTPPath     string `toml:"http-path" json:"httpPath,omitempty"`
53
+			MetricPrefix string `toml:"metric-prefix" json:"metricPrefix,omitempty"`
54
+		} `toml:"prometheus" json:"prometheus,omitempty"`
55
+	} `toml:"stats" json:"stats,omitempty"`
56
+}
57
+
58
+func Parse(rawData []byte) (*Config, error) {
59
+	tomlConf := &tomlConfig{}
60
+	jsonBuf := &bytes.Buffer{}
61
+	conf := &Config{}
62
+
63
+	jsonEncoder := json.NewEncoder(jsonBuf)
64
+	jsonEncoder.SetEscapeHTML(false)
65
+	jsonEncoder.SetIndent("", "")
66
+
67
+	if err := toml.Unmarshal(rawData, tomlConf); err != nil {
68
+		return nil, fmt.Errorf("cannot parse toml config: %w", err)
69
+	}
70
+
71
+	if err := jsonEncoder.Encode(tomlConf); err != nil {
72
+		panic(err)
73
+	}
74
+
75
+	if err := json.NewDecoder(jsonBuf).Decode(conf); err != nil {
76
+		return nil, fmt.Errorf("cannot parse a config: %w", err)
77
+	}
78
+
79
+	return conf, nil
80
+}

+ 36
- 27
internal/config/type_blocklist_uri.go Zobrazit soubor

@@ -8,61 +8,70 @@ import (
8 8
 )
9 9
 
10 10
 type TypeBlocklistURI struct {
11
-	value string
11
+	Value string
12 12
 }
13 13
 
14
-func (c *TypeBlocklistURI) UnmarshalText(data []byte) error {
15
-	if len(data) == 0 {
16
-		return nil
17
-	}
14
+func (t *TypeBlocklistURI) Set(value string) error {
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
+		}
18 22
 
19
-	text := string(data)
20
-	if filepath.IsAbs(text) {
21
-		if _, err := os.Stat(text); os.IsNotExist(err) {
22
-			return fmt.Errorf("filepath %s does not exist", text)
23
+		value, err = filepath.Abs(value)
24
+		if err != nil {
25
+			return fmt.Errorf(
26
+				"value is correct filepath but cannot resolve absolute (%s): %w",
27
+				value, err)
23 28
 		}
24 29
 
25
-		c.value = text
30
+		t.Value = value
26 31
 
27 32
 		return nil
28 33
 	}
29 34
 
30
-	parsedURL, err := url.Parse(text)
35
+	parsedURL, err := url.Parse(value)
31 36
 	if err != nil {
32
-		return fmt.Errorf("incorrect url: %w", err)
37
+		return fmt.Errorf("incorrect url (%s): %w", value, err)
33 38
 	}
34 39
 
35 40
 	switch parsedURL.Scheme {
36
-	case "http", "https": // nolint: goconst
41
+	case "http", "https":
37 42
 	default:
38
-		return fmt.Errorf("unknown schema %s", parsedURL.Scheme)
43
+		return fmt.Errorf("unknown schema %s (%s)", parsedURL.Scheme, value)
39 44
 	}
40 45
 
41 46
 	if parsedURL.Host == "" {
42
-		return fmt.Errorf("incorrect url %s", text)
47
+		return fmt.Errorf("incorrect url %s", value)
43 48
 	}
44 49
 
45
-	c.value = parsedURL.String()
50
+	t.Value = parsedURL.String()
46 51
 
47 52
 	return nil
48 53
 }
49 54
 
50
-func (c TypeBlocklistURI) MarshalText() ([]byte, error) {
51
-	return []byte(c.value), nil
55
+func (t TypeBlocklistURI) Get(defaultValue string) string {
56
+	if t.Value == "" {
57
+		return defaultValue
58
+	}
59
+
60
+	return t.Value
52 61
 }
53 62
 
54
-func (c TypeBlocklistURI) String() string {
55
-	return c.value
63
+func (t TypeBlocklistURI) IsRemote() bool {
64
+	return !filepath.IsAbs(t.Value)
56 65
 }
57 66
 
58
-func (c TypeBlocklistURI) IsRemote() bool {
59
-	return !filepath.IsAbs(c.value)
67
+func (t *TypeBlocklistURI) UnmarshalText(data []byte) error {
68
+	return t.Set(string(data))
60 69
 }
61 70
 
62
-func (c TypeBlocklistURI) Value(defaultValue string) string {
63
-	if c.value == "" {
64
-		return defaultValue
65
-	}
71
+func (t TypeBlocklistURI) MarshalText() ([]byte, error) {
72
+	return []byte(t.String()), nil
73
+}
66 74
 
67
-	return c.value
75
+func (t TypeBlocklistURI) String() string {
76
+	return t.Value
68 77
 }

+ 37
- 101
internal/config/type_blocklist_uri_test.go Zobrazit soubor

@@ -1,12 +1,10 @@
1 1
 package config_test
2 2
 
3 3
 import (
4
-	"crypto/rand"
5
-	"encoding/base64"
6 4
 	"encoding/json"
7 5
 	"os"
8 6
 	"path/filepath"
9
-	"strconv"
7
+	"strings"
10 8
 	"testing"
11 9
 
12 10
 	"github.com/9seconds/mtg/v2/internal/config"
@@ -20,42 +18,28 @@ type typeBlocklistURITestStruct struct {
20 18
 
21 19
 type TypeBlocklistURITestSuite struct {
22 20
 	suite.Suite
23
-}
24
-
25
-func (suite *TypeBlocklistURITestSuite) TestUnmarshalNil() {
26
-	typ := &config.TypeBlocklistURI{}
27
-	suite.NoError(typ.UnmarshalText(nil))
28
-	suite.Empty(typ.String())
29
-}
30 21
 
31
-func (suite *TypeBlocklistURITestSuite) TestUnknownSchema() {
32
-	typ := &config.TypeBlocklistURI{}
33
-	suite.Error(typ.UnmarshalText([]byte("gopher://lalala")))
22
+	directory    string
23
+	absDirectory string
34 24
 }
35 25
 
36
-func (suite *TypeBlocklistURITestSuite) TestEmptyHost() {
37
-	typ := &config.TypeBlocklistURI{}
38
-	suite.Error(typ.UnmarshalText([]byte("https:///path")))
39
-}
26
+func (suite *TypeBlocklistURITestSuite) SetupSuite() {
27
+	dir, _ := os.Getwd()
28
+	absDir, _ := filepath.Abs(dir)
40 29
 
41
-func (suite *TypeBlocklistURITestSuite) TestIncorrectURL() {
42
-	typ := &config.TypeBlocklistURI{}
43
-	suite.Error(typ.UnmarshalText([]byte("h:/--")))
30
+	suite.directory = dir
31
+	suite.absDirectory = absDir
44 32
 }
45 33
 
46 34
 func (suite *TypeBlocklistURITestSuite) TestUnmarshalFail() {
47
-	rnd := make([]byte, 48)
48
-
49
-	rand.Read(rnd) // nolint: errcheck
50
-
51
-	unknownPath := base64.StdEncoding.EncodeToString(rnd)
52
-
53 35
 	testData := []string{
54
-		"1",
55
-		unknownPath,
56
-		"/" + unknownPath,
57
-		"http:/",
58
-		"gopher://lalalal",
36
+		"gopher://lalala",
37
+		"https:///paths",
38
+		"h:/=",
39
+		filepath.Join(suite.directory, "___"),
40
+		filepath.Join(suite.absDirectory, "___"),
41
+		suite.directory,
42
+		suite.absDirectory,
59 43
 	}
60 44
 
61 45
 	for _, v := range testData {
@@ -71,13 +55,12 @@ func (suite *TypeBlocklistURITestSuite) TestUnmarshalFail() {
71 55
 }
72 56
 
73 57
 func (suite *TypeBlocklistURITestSuite) TestUnmarshalOk() {
74
-	dir, _ := os.Getwd()
75
-	dir, _ = filepath.Abs(dir)
76
-
77 58
 	testData := []string{
78 59
 		"http://lalala",
79
-		filepath.Join(dir, "config.go"),
80 60
 		"https://lalala",
61
+		"https://lalala/path",
62
+		filepath.Join(suite.directory, "config.go"),
63
+		filepath.Join(suite.absDirectory, "config.go"),
81 64
 	}
82 65
 
83 66
 	for _, v := range testData {
@@ -92,83 +75,36 @@ func (suite *TypeBlocklistURITestSuite) TestUnmarshalOk() {
92 75
 			testStruct := &typeBlocklistURITestStruct{}
93 76
 
94 77
 			assert.NoError(t, json.Unmarshal(data, testStruct))
95
-			assert.EqualValues(t, value, testStruct.Value.Value(""))
78
+			assert.EqualValues(t, value, testStruct.Value.Get(""))
79
+
80
+			if strings.HasPrefix(value, "http") {
81
+				assert.True(t, testStruct.Value.IsRemote())
82
+			} else {
83
+				assert.False(t, testStruct.Value.IsRemote())
84
+			}
96 85
 		})
97 86
 	}
98 87
 }
99 88
 
100 89
 func (suite *TypeBlocklistURITestSuite) TestMarshalOk() {
101
-	dir, _ := os.Getwd()
102
-	dir, _ = filepath.Abs(dir)
103
-
104
-	testData := []string{
105
-		"http://lalalal",
106
-		filepath.Join(dir, "config.go"),
90
+	testStruct := &typeBlocklistURITestStruct{
91
+		Value: config.TypeBlocklistURI{
92
+			Value: "http://some.url/with/path",
93
+		},
107 94
 	}
108 95
 
109
-	for _, v := range testData {
110
-		name := v
111
-
112
-		data, err := json.Marshal(map[string]string{
113
-			"value": name,
114
-		})
115
-		suite.NoError(err)
116
-
117
-		suite.T().Run(name, func(t *testing.T) {
118
-			testStruct := &typeBlocklistURITestStruct{}
119
-
120
-			assert.NoError(t, json.Unmarshal(data, testStruct))
121
-			assert.Equal(t, name, testStruct.Value.String())
122
-
123
-			marshalled, err := testStruct.Value.MarshalText()
124
-			assert.NoError(t, err)
125
-			assert.Equal(t, name, string(marshalled))
126
-		})
127
-	}
128
-}
129
-
130
-func (suite *TypeBlocklistURITestSuite) TestValue() {
131
-	testStruct := &typeBlocklistURITestStruct{}
132
-
133
-	suite.Equal("http://lalala", testStruct.Value.Value("http://lalala"))
134
-
135
-	data, err := json.Marshal(map[string]string{
136
-		"value": "http://blablabla",
137
-	})
96
+	data, err := json.Marshal(testStruct)
138 97
 	suite.NoError(err)
139
-	suite.NoError(json.Unmarshal(data, testStruct))
140
-
141
-	suite.Equal("http://blablabla", testStruct.Value.Value(""))
98
+	suite.JSONEq(`{"value": "http://some.url/with/path"}`, string(data))
142 99
 }
143 100
 
144
-func (suite *TypeBlocklistURITestSuite) TestIsRemote() {
145
-	dir, _ := os.Getwd()
146
-	dir, _ = filepath.Abs(dir)
147
-
148
-	testData := map[bool]string{
149
-		true:  "http://lalalal",
150
-		false: filepath.Join(dir, "config.go"),
151
-	}
152
-
153
-	for k, v := range testData {
154
-		ok := k
155
-
156
-		data, err := json.Marshal(map[string]string{
157
-			"value": v,
158
-		})
159
-		suite.NoError(err)
160
-
161
-		suite.T().Run(strconv.FormatBool(ok), func(t *testing.T) {
162
-			testStruct := &typeBlocklistURITestStruct{}
163
-			assert.NoError(t, json.Unmarshal(data, testStruct))
101
+func (suite *TypeBlocklistURITestSuite) TestGet() {
102
+	value := config.TypeBlocklistURI{}
103
+	suite.Equal("/path", value.Get("/path"))
164 104
 
165
-			if ok {
166
-				assert.True(t, testStruct.Value.IsRemote())
167
-			} else {
168
-				assert.False(t, testStruct.Value.IsRemote())
169
-			}
170
-		})
171
-	}
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(""))
172 108
 }
173 109
 
174 110
 func TestTypeBlocklistURI(t *testing.T) {

+ 37
- 0
internal/config/type_bool.go Zobrazit soubor

@@ -0,0 +1,37 @@
1
+package config
2
+
3
+import (
4
+	"fmt"
5
+	"strconv"
6
+)
7
+
8
+type TypeBool struct {
9
+	Value bool
10
+}
11
+
12
+func (t *TypeBool) Set(data string) error {
13
+	parsed, err := strconv.ParseBool(data)
14
+	if err != nil {
15
+		return fmt.Errorf("incorrect bool value: %s", data)
16
+	}
17
+
18
+	t.Value = parsed
19
+
20
+	return nil
21
+}
22
+
23
+func (t TypeBool) Get(defaultValue bool) bool {
24
+	return t.Value || defaultValue
25
+}
26
+
27
+func (t *TypeBool) UnmarshalJSON(data []byte) error {
28
+	return t.Set(string(data))
29
+}
30
+
31
+func (t TypeBool) MarshalJSON() ([]byte, error) {
32
+	return []byte(t.String()), nil
33
+}
34
+
35
+func (t TypeBool) String() string {
36
+	return strconv.FormatBool(t.Value)
37
+}

+ 107
- 0
internal/config/type_bool_test.go Zobrazit soubor

@@ -0,0 +1,107 @@
1
+package config_test
2
+
3
+import (
4
+	"encoding/json"
5
+	"fmt"
6
+	"strconv"
7
+	"testing"
8
+
9
+	"github.com/9seconds/mtg/v2/internal/config"
10
+	"github.com/stretchr/testify/assert"
11
+	"github.com/stretchr/testify/suite"
12
+)
13
+
14
+type typeBoolTestStruct struct {
15
+	Value config.TypeBool `json:"value"`
16
+}
17
+
18
+type TypeBoolTestSuite struct {
19
+	suite.Suite
20
+}
21
+
22
+func (suite *TypeBoolTestSuite) TestUnmarshalFail() {
23
+	testData := []interface{}{
24
+		"",
25
+		"np",
26
+		"нет",
27
+		int(10),
28
+		[]int{},
29
+	}
30
+
31
+	for _, v := range testData {
32
+		data, err := json.Marshal(map[string]interface{}{
33
+			"value": v,
34
+		})
35
+		suite.NoError(err)
36
+
37
+		suite.T().Run(fmt.Sprintf("%v", v), func(t *testing.T) {
38
+			assert.Error(t, json.Unmarshal(data, &typeBoolTestStruct{}))
39
+		})
40
+	}
41
+}
42
+
43
+func (suite *TypeBoolTestSuite) TestUnmarshalOk() {
44
+	testData := []bool{
45
+		true,
46
+		false,
47
+	}
48
+
49
+	for _, v := range testData {
50
+		value := v
51
+
52
+		data, err := json.Marshal(map[string]bool{
53
+			"value": v,
54
+		})
55
+		suite.NoError(err)
56
+
57
+		suite.T().Run(strconv.FormatBool(v), func(t *testing.T) {
58
+			testStruct := &typeBoolTestStruct{}
59
+			assert.NoError(t, json.Unmarshal(data, testStruct))
60
+
61
+			if value {
62
+				assert.True(t, testStruct.Value.Value)
63
+			} else {
64
+				assert.False(t, testStruct.Value.Value)
65
+			}
66
+		})
67
+	}
68
+}
69
+
70
+func (suite *TypeBoolTestSuite) TestMarshalOk() {
71
+	for _, v := range []bool{true, false} {
72
+		value := v
73
+
74
+		suite.T().Run(strconv.FormatBool(v), func(t *testing.T) {
75
+			testStruct := typeBoolTestStruct{
76
+				Value: config.TypeBool{
77
+					Value: value,
78
+				},
79
+			}
80
+
81
+			encodedJSON, err := json.Marshal(testStruct)
82
+			assert.NoError(t, err)
83
+
84
+			expectedJSON, err := json.Marshal(map[string]bool{
85
+				"value": value,
86
+			})
87
+			assert.NoError(t, err)
88
+
89
+			assert.JSONEq(t, string(expectedJSON), string(encodedJSON))
90
+		})
91
+	}
92
+}
93
+
94
+func (suite *TypeBoolTestSuite) TestGet() {
95
+	value := config.TypeBool{}
96
+	suite.False(value.Get(false))
97
+	suite.True(value.Get(true))
98
+
99
+	value.Value = true
100
+	suite.True(value.Get(false))
101
+	suite.True(value.Get(true))
102
+}
103
+
104
+func TestTypeBool(t *testing.T) {
105
+	t.Parallel()
106
+	suite.Run(t, &TypeBoolTestSuite{})
107
+}

+ 25
- 24
internal/config/type_bytes.go Zobrazit soubor

@@ -7,48 +7,49 @@ import (
7 7
 	"github.com/alecthomas/units"
8 8
 )
9 9
 
10
+var typeBytesStringCleaner = strings.NewReplacer(" ", "", "\t", "", "IB", "iB")
11
+
10 12
 type TypeBytes struct {
11
-	value units.Base2Bytes
13
+	Value units.Base2Bytes
12 14
 }
13 15
 
14
-func (c *TypeBytes) UnmarshalText(data []byte) error {
15
-	if len(data) == 0 {
16
-		return nil
17
-	}
18
-
19
-	normalizedData := strings.ToUpper(string(data))
20
-	normalizedData = strings.ReplaceAll(normalizedData, "IB", "iB")
16
+func (t *TypeBytes) Set(value string) error {
17
+	normalizedValue := typeBytesStringCleaner.Replace(strings.ToUpper(value))
21 18
 
22
-	value, err := units.ParseBase2Bytes(normalizedData)
19
+	parsedValue, err := units.ParseBase2Bytes(normalizedValue)
23 20
 	if err != nil {
24
-		return fmt.Errorf("incorrect bytes value: %w", err)
21
+		return fmt.Errorf("incorrect bytes value (%v): %w", value, err)
25 22
 	}
26 23
 
27
-	if value < 0 {
28
-		return fmt.Errorf("%d should be positive number", value)
24
+	if parsedValue < 0 {
25
+		return fmt.Errorf("bytes should be positive (%s)", value)
29 26
 	}
30 27
 
31
-	c.value = value
28
+	t.Value = parsedValue
32 29
 
33 30
 	return nil
34 31
 }
35 32
 
36
-func (c TypeBytes) MarshalText() ([]byte, error) {
37
-	return []byte(c.String()), nil
33
+func (t TypeBytes) Get(defaultValue uint) uint {
34
+	if t.Value == 0 {
35
+		return defaultValue
36
+	}
37
+
38
+	return uint(t.Value)
38 39
 }
39 40
 
40
-func (c TypeBytes) String() string {
41
-	if c.value == 0 {
42
-		return ""
43
-	}
41
+func (t *TypeBytes) UnmarshalText(data []byte) error {
42
+	return t.Set(string(data))
43
+}
44 44
 
45
-	return strings.ToLower(c.value.String())
45
+func (t TypeBytes) MarshalText() ([]byte, error) {
46
+	return []byte(t.String()), nil
46 47
 }
47 48
 
48
-func (c TypeBytes) Value(defaultValue uint) uint {
49
-	if c.value == 0 {
50
-		return defaultValue
49
+func (t TypeBytes) String() string {
50
+	if t.Value == 0 {
51
+		return ""
51 52
 	}
52 53
 
53
-	return uint(c.value)
54
+	return strings.ToLower(t.Value.String())
54 55
 }

+ 11
- 45
internal/config/type_bytes_test.go Zobrazit soubor

@@ -17,19 +17,12 @@ type TypeBytesTestSuite struct {
17 17
 	suite.Suite
18 18
 }
19 19
 
20
-func (suite *TypeBytesTestSuite) TestUnmarshalNil() {
21
-	typ := &config.TypeBytes{}
22
-	suite.NoError(typ.UnmarshalText(nil))
23
-	suite.Empty(typ.String())
24
-}
25
-
26 20
 func (suite *TypeBytesTestSuite) TestUnmarshalFail() {
27 21
 	testData := []string{
28 22
 		"1m",
29 23
 		"1",
30 24
 		"-1kb",
31 25
 		"-1kib",
32
-		"-1QB",
33 26
 	}
34 27
 
35 28
 	for _, v := range testData {
@@ -65,53 +58,26 @@ func (suite *TypeBytesTestSuite) TestUnmarshalOk() {
65 58
 			testStruct := &typeBytesTestStruct{}
66 59
 
67 60
 			assert.NoError(t, json.Unmarshal(data, testStruct))
68
-			assert.EqualValues(t, value, testStruct.Value.Value(0))
61
+			assert.EqualValues(t, value, testStruct.Value.Get(0))
69 62
 		})
70 63
 	}
71 64
 }
72 65
 
73 66
 func (suite *TypeBytesTestSuite) TestMarshalOk() {
74
-	testData := []string{
75
-		"1b",
76
-		"1kib",
77
-		"2mib",
78
-	}
79
-
80
-	for _, v := range testData {
81
-		name := v
82
-
83
-		data, err := json.Marshal(map[string]string{
84
-			"value": name,
85
-		})
86
-		suite.NoError(err)
67
+	value := typeBytesTestStruct{}
68
+	suite.NoError(value.Value.Set("1kib"))
87 69
 
88
-		suite.T().Run(name, func(t *testing.T) {
89
-			testStruct := &typeBytesTestStruct{}
90
-
91
-			assert.NoError(t, json.Unmarshal(data, testStruct))
92
-			assert.Equal(t, name, testStruct.Value.String())
93
-
94
-			marshalled, err := testStruct.Value.MarshalText()
95
-			assert.NoError(t, err)
96
-			assert.Equal(t, name, string(marshalled))
97
-		})
98
-	}
70
+	data, err := json.Marshal(value)
71
+	suite.NoError(err)
72
+	suite.JSONEq(`{"value": "1kib"}`, string(data))
99 73
 }
100 74
 
101
-func (suite *TypeBytesTestSuite) TestValue() {
102
-	testStruct := &typeBytesTestStruct{}
103
-
104
-	suite.EqualValues(0, testStruct.Value.Value(0))
105
-	suite.EqualValues(1, testStruct.Value.Value(1))
106
-
107
-	data, err := json.Marshal(map[string]string{
108
-		"value": "1kb",
109
-	})
110
-	suite.NoError(err)
111
-	suite.NoError(json.Unmarshal(data, testStruct))
75
+func (suite *TypeBytesTestSuite) TestGet() {
76
+	value := config.TypeBytes{}
77
+	suite.EqualValues(1000, value.Get(1000))
112 78
 
113
-	suite.EqualValues(1024, testStruct.Value.Value(0))
114
-	suite.EqualValues(1024, testStruct.Value.Value(1))
79
+	suite.NoError(value.Set("1mib"))
80
+	suite.EqualValues(1048576, value.Get(1000))
115 81
 }
116 82
 
117 83
 func TestTypeBytes(t *testing.T) {

+ 45
- 0
internal/config/type_concurrency.go Zobrazit soubor

@@ -0,0 +1,45 @@
1
+package config
2
+
3
+import (
4
+	"fmt"
5
+	"strconv"
6
+)
7
+
8
+type TypeConcurrency struct {
9
+	Value uint
10
+}
11
+
12
+func (t *TypeConcurrency) Set(value string) error {
13
+	concurrencyValue, err := strconv.ParseUint(value, 10, 16) // nolint: gomnd
14
+	if err != nil {
15
+		return fmt.Errorf("value is not uint (%s): %w", value, err)
16
+	}
17
+
18
+	if concurrencyValue == 0 {
19
+		return fmt.Errorf("value should be >0 (%s)", value)
20
+	}
21
+
22
+	t.Value = uint(concurrencyValue)
23
+
24
+	return nil
25
+}
26
+
27
+func (t TypeConcurrency) Get(defaultValue uint) uint {
28
+	if t.Value == 0 {
29
+		return defaultValue
30
+	}
31
+
32
+	return t.Value
33
+}
34
+
35
+func (t *TypeConcurrency) UnmarshalJSON(data []byte) error {
36
+	return t.Set(string(data))
37
+}
38
+
39
+func (t TypeConcurrency) MarshalJSON() ([]byte, error) {
40
+	return []byte(t.String()), nil
41
+}
42
+
43
+func (t TypeConcurrency) String() string {
44
+	return strconv.FormatUint(uint64(t.Value), 10) // nolint: gomnd
45
+}

+ 73
- 0
internal/config/type_concurrency_test.go Zobrazit soubor

@@ -0,0 +1,73 @@
1
+package config_test
2
+
3
+import (
4
+	"encoding/json"
5
+	"testing"
6
+
7
+	"github.com/9seconds/mtg/v2/internal/config"
8
+	"github.com/stretchr/testify/assert"
9
+	"github.com/stretchr/testify/suite"
10
+)
11
+
12
+type typeConcurrencyTestStruct struct {
13
+	Value config.TypeConcurrency `json:"value"`
14
+}
15
+
16
+type TypeConcurrencyTestSuite struct {
17
+	suite.Suite
18
+}
19
+
20
+func (suite *TypeConcurrencyTestSuite) TestUnmarshalFail() {
21
+	testData := []string{
22
+		"-1",
23
+		"0",
24
+		"0.0",
25
+		"1.0",
26
+		"1.1",
27
+		".",
28
+		"some_value",
29
+	}
30
+
31
+	for _, v := range testData {
32
+		data, err := json.Marshal(map[string]string{
33
+			"value": v,
34
+		})
35
+		suite.NoError(err)
36
+
37
+		suite.T().Run(v, func(t *testing.T) {
38
+			assert.Error(t, json.Unmarshal(data, &typeConcurrencyTestStruct{}))
39
+		})
40
+	}
41
+}
42
+
43
+func (suite *TypeConcurrencyTestSuite) TestUnmarshalOk() {
44
+	testStruct := &typeConcurrencyTestStruct{}
45
+
46
+	suite.NoError(json.Unmarshal([]byte(`{"value": 1}`), testStruct))
47
+	suite.EqualValues(1, testStruct.Value.Get(2))
48
+}
49
+
50
+func (suite *TypeConcurrencyTestSuite) TestMarshalOk() {
51
+	testStruct := &typeConcurrencyTestStruct{
52
+		Value: config.TypeConcurrency{
53
+			Value: 2,
54
+		},
55
+	}
56
+
57
+	data, err := json.Marshal(testStruct)
58
+	suite.NoError(err)
59
+	suite.JSONEq(`{"value": 2}`, string(data))
60
+}
61
+
62
+func (suite *TypeConcurrencyTestSuite) TestGet() {
63
+	value := config.TypeConcurrency{}
64
+	suite.EqualValues(1, value.Get(1))
65
+
66
+	value.Value = 3
67
+	suite.EqualValues(3, value.Get(1))
68
+}
69
+
70
+func TestTypeConcurrency(t *testing.T) {
71
+	t.Parallel()
72
+	suite.Run(t, &TypeConcurrencyTestSuite{})
73
+}

+ 26
- 19
internal/config/type_duration.go Zobrazit soubor

@@ -6,41 +6,48 @@ import (
6 6
 	"time"
7 7
 )
8 8
 
9
+var typeDurationStringCleaner = strings.NewReplacer(" ", "", "\t", "")
10
+
9 11
 type TypeDuration struct {
10
-	value time.Duration
12
+	Value time.Duration
11 13
 }
12 14
 
13
-func (c *TypeDuration) UnmarshalText(data []byte) error {
14
-	if len(data) == 0 {
15
-		return nil
16
-	}
17
-
18
-	dur, err := time.ParseDuration(strings.ToLower(string(data)))
15
+func (t *TypeDuration) Set(value string) error {
16
+	parsedValue, err := time.ParseDuration(
17
+		typeDurationStringCleaner.Replace(strings.ToLower(value)))
19 18
 	if err != nil {
20
-		return fmt.Errorf("incorrect duration: %w", err)
19
+		return fmt.Errorf("incorrect duration (%s): %w", value, err)
21 20
 	}
22 21
 
23
-	if dur < 0 {
24
-		return fmt.Errorf("%s should be positive duration", dur)
22
+	if parsedValue < 0 {
23
+		return fmt.Errorf("duration has to be a positive: %s", value)
25 24
 	}
26 25
 
27
-	c.value = dur
26
+	t.Value = parsedValue
28 27
 
29 28
 	return nil
30 29
 }
31 30
 
32
-func (c TypeDuration) MarshalText() ([]byte, error) {
33
-	return []byte(c.value.String()), nil
31
+func (t TypeDuration) Get(defaultValue time.Duration) time.Duration {
32
+	if t.Value == 0 {
33
+		return defaultValue
34
+	}
35
+
36
+	return t.Value
34 37
 }
35 38
 
36
-func (c TypeDuration) String() string {
37
-	return c.value.String()
39
+func (t *TypeDuration) UnmarshalText(data []byte) error {
40
+	return t.Set(string(data))
38 41
 }
39 42
 
40
-func (c TypeDuration) Value(defaultValue time.Duration) time.Duration {
41
-	if c.value == 0 {
42
-		return defaultValue
43
+func (t TypeDuration) MarshalText() ([]byte, error) {
44
+	return []byte(t.String()), nil
45
+}
46
+
47
+func (t TypeDuration) String() string {
48
+	if t.Value == 0 {
49
+		return ""
43 50
 	}
44 51
 
45
-	return c.value
52
+	return t.Value.String()
46 53
 }

+ 33
- 41
internal/config/type_duration_test.go Zobrazit soubor

@@ -18,18 +18,12 @@ type TypeDurationTestSuite struct {
18 18
 	suite.Suite
19 19
 }
20 20
 
21
-func (suite *TypeDurationTestSuite) TestUnmarshalNil() {
22
-	typ := &config.TypeDuration{}
23
-	suite.NoError(typ.UnmarshalText(nil))
24
-	suite.EqualValues(0, typ.Value(0))
25
-}
26
-
27 21
 func (suite *TypeDurationTestSuite) TestUnmarshalFail() {
28 22
 	testData := []string{
29
-		"1t",
30
-		"1",
31 23
 		"-1s",
32
-		"-1h",
24
+		"1 seconds ago",
25
+		"1s ago",
26
+		"",
33 27
 	}
34 28
 
35 29
 	for _, v := range testData {
@@ -47,8 +41,11 @@ func (suite *TypeDurationTestSuite) TestUnmarshalFail() {
47 41
 func (suite *TypeDurationTestSuite) TestUnmarshalOk() {
48 42
 	testData := map[string]time.Duration{
49 43
 		"1s":   time.Second,
50
-		"1m":   time.Minute,
51
-		"2h1s": 2*time.Hour + time.Second,
44
+		"0":    0 * time.Second,
45
+		"0s":   0 * time.Second,
46
+		"1\tM": time.Minute,
47
+		"1H":   time.Hour,
48
+		"1 h":  time.Hour,
52 49
 	}
53 50
 
54 51
 	for k, v := range testData {
@@ -63,53 +60,48 @@ func (suite *TypeDurationTestSuite) TestUnmarshalOk() {
63 60
 			testStruct := &typeDurationTestStruct{}
64 61
 
65 62
 			assert.NoError(t, json.Unmarshal(data, testStruct))
66
-			assert.Equal(t, value, testStruct.Value.Value(0))
63
+			assert.Equal(t, value, testStruct.Value.Value)
67 64
 		})
68 65
 	}
69 66
 }
70 67
 
71 68
 func (suite *TypeDurationTestSuite) TestMarshalOk() {
72
-	testData := []string{
73
-		"1s",
74
-		"1m0s",
75
-		"2h0m1s",
69
+	testData := map[string]string{
70
+		"1s":  "1s",
71
+		"0":   "",
72
+		"0s":  "",
73
+		"0ms": "",
74
+		"1 H": "1h0m0s",
76 75
 	}
77 76
 
78
-	for _, v := range testData {
79
-		name := v
80
-
81
-		data, err := json.Marshal(map[string]string{
82
-			"value": name,
83
-		})
84
-		suite.NoError(err)
77
+	for k, v := range testData {
78
+		value := k
79
+		expected := v
85 80
 
86
-		suite.T().Run(name, func(t *testing.T) {
81
+		suite.T().Run(value, func(t *testing.T) {
87 82
 			testStruct := &typeDurationTestStruct{}
88 83
 
89
-			assert.NoError(t, json.Unmarshal(data, testStruct))
90
-			assert.Equal(t, name, testStruct.Value.String())
84
+			assert.NoError(t, testStruct.Value.Set(value))
85
+
86
+			data, err := json.Marshal(testStruct)
87
+			assert.NoError(t, err)
91 88
 
92
-			marshalled, err := testStruct.Value.MarshalText()
89
+			expectedJSON, err := json.Marshal(map[string]string{
90
+				"value": expected,
91
+			})
93 92
 			assert.NoError(t, err)
94
-			assert.Equal(t, name, string(marshalled))
93
+
94
+			assert.JSONEq(t, string(expectedJSON), string(data))
95 95
 		})
96 96
 	}
97 97
 }
98 98
 
99
-func (suite *TypeDurationTestSuite) TestValue() {
100
-	testStruct := &typeDurationTestStruct{}
101
-
102
-	suite.EqualValues(0, testStruct.Value.Value(0))
103
-	suite.Equal(time.Second, testStruct.Value.Value(time.Second))
104
-
105
-	data, err := json.Marshal(map[string]string{
106
-		"value": "1s",
107
-	})
108
-	suite.NoError(err)
109
-	suite.NoError(json.Unmarshal(data, testStruct))
99
+func (suite *TypeDurationTestSuite) TestGet() {
100
+	value := config.TypeDuration{}
101
+	suite.Equal(time.Second, value.Get(time.Second))
110 102
 
111
-	suite.Equal(time.Second, testStruct.Value.Value(0))
112
-	suite.Equal(time.Second, testStruct.Value.Value(time.Minute))
103
+	value.Value = 3 * time.Second
104
+	suite.Equal(3*time.Second, value.Get(time.Hour))
113 105
 }
114 106
 
115 107
 func TestTypeDuration(t *testing.T) {

+ 20
- 16
internal/config/type_error_rate.go Zobrazit soubor

@@ -8,36 +8,40 @@ import (
8 8
 const typeErrorRateIgnoreLess = 1e-8
9 9
 
10 10
 type TypeErrorRate struct {
11
-	value float64
11
+	Value float64
12 12
 }
13 13
 
14
-func (c *TypeErrorRate) UnmarshalJSON(data []byte) error {
15
-	value, err := strconv.ParseFloat(string(data), 64)
14
+func (t *TypeErrorRate) Set(value string) error {
15
+	parsedValue, err := strconv.ParseFloat(value, 64) // nolint: gomnd
16 16
 	if err != nil {
17
-		return fmt.Errorf("incorrect float value: %w", err)
17
+		return fmt.Errorf("value is not a float (%s): %w", value, err)
18 18
 	}
19 19
 
20
-	if value <= 0 || value >= 100 {
21
-		return fmt.Errorf("%f should be 0 < x < 100", value)
20
+	if parsedValue <= 0.0 || parsedValue >= 100.0 {
21
+		return fmt.Errorf("value should be 0 < x < 100 (%s)", value)
22 22
 	}
23 23
 
24
-	c.value = value
24
+	t.Value = parsedValue
25 25
 
26 26
 	return nil
27 27
 }
28 28
 
29
-func (c *TypeErrorRate) MarshalText() ([]byte, error) {
30
-	return []byte(c.String()), nil
29
+func (t TypeErrorRate) Get(defaultValue float64) float64 {
30
+	if t.Value < typeErrorRateIgnoreLess {
31
+		return defaultValue
32
+	}
33
+
34
+	return t.Value
31 35
 }
32 36
 
33
-func (c TypeErrorRate) String() string {
34
-	return strconv.FormatFloat(c.value, 'f', -1, 64)
37
+func (t *TypeErrorRate) UnmarshalJSON(data []byte) error {
38
+	return t.Set(string(data))
35 39
 }
36 40
 
37
-func (c TypeErrorRate) Value(defaultValue float64) float64 {
38
-	if c.value < typeErrorRateIgnoreLess {
39
-		return defaultValue
40
-	}
41
+func (t TypeErrorRate) MarshalJSON() ([]byte, error) {
42
+	return []byte(t.String()), nil
43
+}
41 44
 
42
-	return c.value
45
+func (t TypeErrorRate) String() string {
46
+	return strconv.FormatFloat(t.Value, 'f', -1, 64) // nolint: gomnd
43 47
 }

+ 33
- 77
internal/config/type_error_rate_test.go Zobrazit soubor

@@ -2,7 +2,6 @@ package config_test
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"strconv"
6 5
 	"testing"
7 6
 
8 7
 	"github.com/9seconds/mtg/v2/internal/config"
@@ -19,104 +18,61 @@ type TypeErrorRateTestSuite struct {
19 18
 }
20 19
 
21 20
 func (suite *TypeErrorRateTestSuite) TestUnmarshalFail() {
22
-	testData := []float64{
23
-		1000,
24
-		-100,
25
-		-0.0001,
21
+	testData := []string{
22
+		"",
23
+		"1s",
24
+		"1,",
25
+		"1,2",
26
+		".",
27
+		"3.4.5",
28
+		"3.5.",
29
+		".3.5",
30
+		"some word",
31
+		"1e2",
32
+		"-1.0",
26 33
 	}
27 34
 
28 35
 	for _, v := range testData {
29
-		data, err := json.Marshal(map[string]float64{
36
+		data, err := json.Marshal(map[string]string{
30 37
 			"value": v,
31 38
 		})
32 39
 		suite.NoError(err)
33 40
 
34
-		suite.T().Run(strconv.FormatFloat(v, 'f', -1, 64), func(t *testing.T) {
41
+		suite.T().Run(v, func(t *testing.T) {
35 42
 			assert.Error(t, json.Unmarshal(data, &typeErrorRateTestStruct{}))
36 43
 		})
37 44
 	}
38
-
39
-	data, err := json.Marshal(map[string]string{
40
-		"value": "hello",
41
-	})
42
-	suite.NoError(err)
43
-	suite.Error(json.Unmarshal(data, &typeErrorRateTestStruct{}))
44 45
 }
45 46
 
46 47
 func (suite *TypeErrorRateTestSuite) TestUnmarshalOk() {
47
-	testData := []float64{
48
-		1,
49
-		55.5,
50
-		0.0001,
51
-		1e-6,
52
-	}
53
-
54
-	for _, v := range testData {
55
-		value := v
56
-
57
-		data, err := json.Marshal(map[string]float64{
58
-			"value": v,
59
-		})
60
-		suite.NoError(err)
61
-
62
-		suite.T().Run(strconv.FormatFloat(v, 'f', -1, 64), func(t *testing.T) {
63
-			testStruct := &typeErrorRateTestStruct{}
48
+	data, err := json.Marshal(map[string]float64{
49
+		"value": 1.0,
50
+	})
51
+	suite.NoError(err)
64 52
 
65
-			assert.NoError(t, json.Unmarshal(data, testStruct))
66
-			assert.InEpsilon(t, value, testStruct.Value.Value(0), 1e-10)
67
-		})
68
-	}
53
+	testStruct := &typeErrorRateTestStruct{}
54
+	suite.NoError(json.Unmarshal(data, testStruct))
55
+	suite.InEpsilon(1.0, testStruct.Value.Value, 1e-10)
69 56
 }
70 57
 
71 58
 func (suite *TypeErrorRateTestSuite) TestMarshalOk() {
72
-	testData := []float64{
73
-		1,
74
-		55.5,
75
-		0.0001,
76
-		1e-6,
59
+	testStruct := typeErrorRateTestStruct{
60
+		Value: config.TypeErrorRate{
61
+			Value: 1.01,
62
+		},
77 63
 	}
78 64
 
79
-	for _, v := range testData {
80
-		value := v
81
-
82
-		data, err := json.Marshal(map[string]float64{
83
-			"value": v,
84
-		})
85
-		suite.NoError(err)
86
-
87
-		suite.T().Run(strconv.FormatFloat(v, 'f', -1, 64), func(t *testing.T) {
88
-			testStruct := &typeErrorRateTestStruct{}
89
-
90
-			assert.NoError(t, json.Unmarshal(data, testStruct))
91
-
92
-			parsed, err := strconv.ParseFloat(testStruct.Value.String(), 64)
93
-			assert.NoError(t, err)
94
-			assert.InEpsilon(t, value, parsed, 1e-10)
95
-
96
-			marshalled, err := testStruct.Value.MarshalText()
97
-			assert.NoError(t, err)
98
-
99
-			parsed, err = strconv.ParseFloat(string(marshalled), 64)
100
-			assert.NoError(t, err)
101
-			assert.InEpsilon(t, value, parsed, 1e-10)
102
-		})
103
-	}
65
+	encodedJSON, err := json.Marshal(testStruct)
66
+	suite.NoError(err)
67
+	suite.JSONEq(`{"value": 1.01}`, string(encodedJSON))
104 68
 }
105 69
 
106
-func (suite *TypeErrorRateTestSuite) TestValue() {
107
-	testStruct := &typeErrorRateTestStruct{}
108
-
109
-	suite.InEpsilon(1, testStruct.Value.Value(1), 1e-10)
110
-	suite.InEpsilon(2, testStruct.Value.Value(2), 1e-10)
111
-
112
-	data, err := json.Marshal(map[string]float64{
113
-		"value": 1,
114
-	})
115
-	suite.NoError(err)
116
-	suite.NoError(json.Unmarshal(data, testStruct))
70
+func (suite *TypeErrorRateTestSuite) TestGet() {
71
+	value := config.TypeErrorRate{}
72
+	suite.InEpsilon(1.0, value.Get(1.0), 1e-10)
117 73
 
118
-	suite.InEpsilon(1, testStruct.Value.Value(2), 1e-10)
119
-	suite.InEpsilon(1, testStruct.Value.Value(3), 1e-10)
74
+	value.Value = 5.0
75
+	suite.InEpsilon(5.0, value.Get(1.0), 1e-10)
120 76
 }
121 77
 
122 78
 func TestTypeErrorRate(t *testing.T) {

+ 30
- 34
internal/config/type_hostport.go Zobrazit soubor

@@ -7,61 +7,57 @@ import (
7 7
 )
8 8
 
9 9
 type TypeHostPort struct {
10
-	host TypeIP
11
-	port TypePort
10
+	Value string
11
+	Host  string
12
+	Port  uint
12 13
 }
13 14
 
14
-func (c *TypeHostPort) UnmarshalText(data []byte) error {
15
-	if len(data) == 0 {
16
-		return nil
15
+func (t *TypeHostPort) Set(value string) error {
16
+	host, port, err := net.SplitHostPort(value)
17
+	if err != nil {
18
+		return fmt.Errorf("incorrect host:port value (%v): %w", value, err)
17 19
 	}
18 20
 
19
-	text := string(data)
20
-
21
-	host, port, err := net.SplitHostPort(text)
21
+	portValue, err := strconv.ParseUint(port, 10, 16) // nolint: gomnd
22 22
 	if err != nil {
23
-		return fmt.Errorf("incorrect host:port syntax: %w", err)
23
+		return fmt.Errorf("incorrect port number (%v): %w", value, err)
24 24
 	}
25 25
 
26
-	if port == "" {
27
-		return fmt.Errorf("port in %s host:port pair cannot be empty", text)
26
+	if portValue == 0 {
27
+		return fmt.Errorf("incorrect port number (%s)", value)
28 28
 	}
29 29
 
30
-	if err := c.port.UnmarshalJSON([]byte(port)); err != nil {
31
-		return fmt.Errorf("incorrect port in host:port: %w", err)
30
+	if host == "" {
31
+		return fmt.Errorf("empty host: %s", value)
32 32
 	}
33 33
 
34
-	if err := c.host.UnmarshalText([]byte(host)); err != nil {
35
-		return fmt.Errorf("incorrect host: %w", err)
34
+	if net.ParseIP(host) == nil {
35
+		return fmt.Errorf("host is not an IP address: %s", value)
36 36
 	}
37 37
 
38
+	t.Value = net.JoinHostPort(host, port)
39
+	t.Port = uint(portValue)
40
+	t.Host = host
41
+
38 42
 	return nil
39 43
 }
40 44
 
41
-func (c TypeHostPort) MarshalText() ([]byte, error) {
42
-	return []byte(c.String()), nil
43
-}
45
+func (t TypeHostPort) Get(defaultValue string) string {
46
+	if t.Value == "" {
47
+		return defaultValue
48
+	}
44 49
 
45
-func (c TypeHostPort) String() string {
46
-	return c.Value(net.IP{}, 0)
50
+	return t.Value
47 51
 }
48 52
 
49
-func (c TypeHostPort) HostValue(defaultValue net.IP) net.IP {
50
-	return c.host.Value(defaultValue)
53
+func (t *TypeHostPort) UnmarshalText(data []byte) error {
54
+	return t.Set(string(data))
51 55
 }
52 56
 
53
-func (c TypeHostPort) PortValue(defaultValue uint) uint {
54
-	return c.port.Value(defaultValue)
57
+func (t TypeHostPort) MarshalText() ([]byte, error) {
58
+	return []byte(t.String()), nil
55 59
 }
56 60
 
57
-func (c TypeHostPort) Value(defaultHostValue net.IP, defaultPortValue uint) string {
58
-	host := c.HostValue(defaultHostValue)
59
-	port := c.PortValue(defaultPortValue)
60
-
61
-	hostStr := ""
62
-	if len(host) > 0 {
63
-		hostStr = host.String()
64
-	}
65
-
66
-	return net.JoinHostPort(hostStr, strconv.Itoa(int(port)))
61
+func (t TypeHostPort) String() string {
62
+	return t.Value
67 63
 }

+ 21
- 48
internal/config/type_hostport_test.go Zobrazit soubor

@@ -2,7 +2,6 @@ package config_test
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"net"
6 5
 	"testing"
7 6
 
8 7
 	"github.com/9seconds/mtg/v2/internal/config"
@@ -20,11 +19,13 @@ type TypeHostPortTestSuite struct {
20 19
 
21 20
 func (suite *TypeHostPortTestSuite) TestUnmarshalFail() {
22 21
 	testData := []string{
23
-		"10.0.0.10:aaa",
24
-		"10.0.0.10:",
25 22
 		":",
26
-		"xxx",
27
-		"xxx:80",
23
+		":800",
24
+		"127.0.0.1:8000000",
25
+		"12...:80",
26
+		"",
27
+		"localhost",
28
+		"google.com:",
28 29
 	}
29 30
 
30 31
 	for _, v := range testData {
@@ -41,9 +42,8 @@ func (suite *TypeHostPortTestSuite) TestUnmarshalFail() {
41 42
 
42 43
 func (suite *TypeHostPortTestSuite) TestUnmarshalOk() {
43 44
 	testData := []string{
44
-		"10.0.0.10:80",
45
-		"0.0.0.0:80",
46
-		":8000",
45
+		"127.0.0.1:80",
46
+		"10.0.0.10:6553",
47 47
 	}
48 48
 
49 49
 	for _, v := range testData {
@@ -56,57 +56,30 @@ func (suite *TypeHostPortTestSuite) TestUnmarshalOk() {
56 56
 
57 57
 		suite.T().Run(v, func(t *testing.T) {
58 58
 			testStruct := &typeHostPortTestStruct{}
59
-
60 59
 			assert.NoError(t, json.Unmarshal(data, testStruct))
61
-			assert.EqualValues(t, value, testStruct.Value.Value(nil, 0))
60
+			assert.Equal(t, value, testStruct.Value.Value)
62 61
 		})
63 62
 	}
64 63
 }
65 64
 
66 65
 func (suite *TypeHostPortTestSuite) TestMarshalOk() {
67
-	testData := []string{
68
-		"10.0.0.10:80",
69
-		"0.0.0.0:80",
70
-		":8000",
66
+	testStruct := typeHostPortTestStruct{
67
+		Value: config.TypeHostPort{
68
+			Value: "127.0.0.1:8000",
69
+		},
71 70
 	}
72 71
 
73
-	for _, v := range testData {
74
-		value := v
75
-
76
-		data, err := json.Marshal(map[string]string{
77
-			"value": v,
78
-		})
79
-		suite.NoError(err)
80
-
81
-		suite.T().Run(v, func(t *testing.T) {
82
-			testStruct := &typeHostPortTestStruct{}
83
-
84
-			assert.NoError(t, json.Unmarshal(data, testStruct))
85
-			assert.Equal(t, value, testStruct.Value.String())
86
-
87
-			marshalled, err := testStruct.Value.MarshalText()
88
-			assert.NoError(t, err)
89
-			assert.Equal(t, value, string(marshalled))
90
-		})
91
-	}
72
+	data, err := json.Marshal(testStruct)
73
+	suite.NoError(err)
74
+	suite.JSONEq(`{"value": "127.0.0.1:8000"}`, string(data))
92 75
 }
93 76
 
94
-func (suite *TypeHostPortTestSuite) TestValue() {
95
-	testStruct := &typeHostPortTestStruct{}
96
-
97
-	suite.EqualValues("127.0.0.1:80",
98
-		testStruct.Value.Value(net.ParseIP("127.0.0.1"), 80))
99
-	suite.EqualValues("127.1.0.1:80",
100
-		testStruct.Value.Value(net.ParseIP("127.1.0.1"), 80))
101
-
102
-	data, err := json.Marshal(map[string]string{
103
-		"value": "127.0.0.1:80",
104
-	})
105
-	suite.NoError(err)
106
-	suite.NoError(json.Unmarshal(data, testStruct))
77
+func (suite *TypeHostPortTestSuite) TestGet() {
78
+	value := config.TypeHostPort{}
79
+	suite.Equal("127.0.0.1:9000", value.Get("127.0.0.1:9000"))
107 80
 
108
-	suite.EqualValues("127.0.0.1:80", testStruct.Value.Value(nil, 0))
109
-	suite.EqualValues("127.0.0.1:80", testStruct.Value.Value(net.ParseIP("10.0.0.10"), 3000))
81
+	value.Value = "127.0.0.1:80"
82
+	suite.Equal("127.0.0.1:80", value.Get("127.0.0.1:9000"))
110 83
 }
111 84
 
112 85
 func TestTypeHostPort(t *testing.T) {

+ 16
- 18
internal/config/type_http_path.go Zobrazit soubor

@@ -3,33 +3,31 @@ package config
3 3
 import "strings"
4 4
 
5 5
 type TypeHTTPPath struct {
6
-	value string
6
+	Value string
7 7
 }
8 8
 
9
-func (c *TypeHTTPPath) UnmarshalText(data []byte) error {
10
-	if len(data) > 0 {
11
-		c.value = "/" + strings.Trim(string(data), "/")
12
-	}
9
+func (t *TypeHTTPPath) Set(value string) error {
10
+	t.Value = "/" + strings.Trim(value, "/")
13 11
 
14 12
 	return nil
15 13
 }
16 14
 
17
-func (c TypeHTTPPath) MarshalText() ([]byte, error) {
18
-	return []byte(c.String()), nil
19
-}
20
-
21
-func (c TypeHTTPPath) String() string {
22
-	if c.value == "" {
23
-		return "/"
15
+func (t TypeHTTPPath) Get(defaultValue string) string {
16
+	if t.Value == "" {
17
+		return defaultValue
24 18
 	}
25 19
 
26
-	return c.value
20
+	return t.Value
27 21
 }
28 22
 
29
-func (c TypeHTTPPath) Value(defaultValue string) string {
30
-	if c.value == "" {
31
-		return defaultValue
32
-	}
23
+func (t *TypeHTTPPath) UnmarshalText(data []byte) error {
24
+	return t.Set(string(data))
25
+}
26
+
27
+func (t TypeHTTPPath) MarshalText() ([]byte, error) {
28
+	return []byte(t.String()), nil
29
+}
33 30
 
34
-	return c.value
31
+func (t TypeHTTPPath) String() string {
32
+	return t.Value
35 33
 }

+ 24
- 48
internal/config/type_http_path_test.go Zobrazit soubor

@@ -17,72 +17,48 @@ type TypeHTTPPathTestSuite struct {
17 17
 	suite.Suite
18 18
 }
19 19
 
20
-func (suite *TypeHTTPPathTestSuite) TestUnmarshal() {
21
-	testData := []string{
22
-		"/hello",
23
-		"hello",
24
-		"hello/",
25
-		"/hello/",
26
-	}
27
-
28
-	for _, v := range testData {
29
-		data, err := json.Marshal(map[string]string{
30
-			"value": v,
31
-		})
32
-		suite.NoError(err)
33
-
34
-		suite.T().Run(v, func(t *testing.T) {
35
-			testStruct := &typeHTTPPathTestStruct{}
36
-
37
-			assert.NoError(t, json.Unmarshal(data, testStruct))
38
-			assert.Equal(t, "/hello", testStruct.Value.Value(""))
39
-		})
40
-	}
41
-}
42
-
43
-func (suite *TypeHTTPPathTestSuite) TestMarshalOk() {
20
+func (suite *TypeHTTPPathTestSuite) TestUnmarshalOk() {
44 21
 	testData := map[string]string{
45
-		"":        "/",
46
-		"/hello":  "/hello",
47
-		"/hello/": "/hello",
48
-		"hello/":  "/hello",
49
-		"hello":   "/hello",
22
+		"":      "/",
23
+		"/":     "/",
24
+		"/path": "/path",
25
+		"path":  "/path",
50 26
 	}
51 27
 
52 28
 	for k, v := range testData {
53
-		toPass := k
54
-		compareWith := v
29
+		value := v
55 30
 
56 31
 		data, err := json.Marshal(map[string]string{
57
-			"value": toPass,
32
+			"value": k,
58 33
 		})
59 34
 		suite.NoError(err)
60 35
 
61
-		suite.T().Run(toPass, func(t *testing.T) {
36
+		suite.T().Run(k, func(t *testing.T) {
62 37
 			testStruct := &typeHTTPPathTestStruct{}
63
-
64 38
 			assert.NoError(t, json.Unmarshal(data, testStruct))
65
-			assert.Equal(t, compareWith, testStruct.Value.String())
66
-
67
-			marshalled, err := testStruct.Value.MarshalText()
68
-			assert.NoError(t, err)
69
-			assert.Equal(t, compareWith, string(marshalled))
39
+			assert.Equal(t, value, testStruct.Value.Get(""))
70 40
 		})
71 41
 	}
72 42
 }
73 43
 
74
-func (suite *TypeHTTPPathTestSuite) TestValue() {
75
-	testStruct := &typeHTTPPathTestStruct{}
76
-
77
-	suite.Equal("/hello", testStruct.Value.Value("/hello"))
44
+func (suite *TypeHTTPPathTestSuite) TestMarshalOk() {
45
+	value := typeHTTPPathTestStruct{
46
+		Value: config.TypeHTTPPath{
47
+			Value: "/path",
48
+		},
49
+	}
78 50
 
79
-	data, err := json.Marshal(map[string]string{
80
-		"value": "/map",
81
-	})
51
+	data, err := json.Marshal(value)
82 52
 	suite.NoError(err)
83
-	suite.NoError(json.Unmarshal(data, testStruct))
53
+	suite.JSONEq(`{"value": "/path"}`, string(data))
54
+}
55
+
56
+func (suite *TypeHTTPPathTestSuite) TestGet() {
57
+	value := config.TypeHTTPPath{}
58
+	suite.Equal("/hello", value.Get("/hello"))
84 59
 
85
-	suite.Equal("/map", testStruct.Value.Value("/hello"))
60
+	suite.NoError(value.Set("/lalala"))
61
+	suite.Equal("/lalala", value.Get("/hello"))
86 62
 }
87 63
 
88 64
 func TestTypeHTTPPath(t *testing.T) {

+ 20
- 20
internal/config/type_ip.go Zobrazit soubor

@@ -6,40 +6,40 @@ import (
6 6
 )
7 7
 
8 8
 type TypeIP struct {
9
-	value net.IP
9
+	Value net.IP
10 10
 }
11 11
 
12
-func (c *TypeIP) UnmarshalText(data []byte) error {
13
-	if len(data) == 0 {
14
-		return nil
15
-	}
16
-
17
-	ip := net.ParseIP(string(data))
12
+func (t *TypeIP) Set(value string) error {
13
+	ip := net.ParseIP(value)
18 14
 	if ip == nil {
19
-		return fmt.Errorf("incorrect ip address: %s", string(data))
15
+		return fmt.Errorf("incorret ip %s", value)
20 16
 	}
21 17
 
22
-	c.value = ip
18
+	t.Value = ip
23 19
 
24 20
 	return nil
25 21
 }
26 22
 
27
-func (c *TypeIP) MarshalText() ([]byte, error) {
28
-	return []byte(c.String()), nil
23
+func (t *TypeIP) Get(defaultValue net.IP) net.IP {
24
+	if len(t.Value) == 0 {
25
+		return defaultValue
26
+	}
27
+
28
+	return t.Value
29 29
 }
30 30
 
31
-func (c TypeIP) String() string {
32
-	if len(c.value) > 0 {
33
-		return c.value.String()
34
-	}
31
+func (t *TypeIP) UnmarshalText(data []byte) error {
32
+	return t.Set(string(data))
33
+}
35 34
 
36
-	return ""
35
+func (t TypeIP) MarshalText() ([]byte, error) {
36
+	return []byte(t.String()), nil
37 37
 }
38 38
 
39
-func (c TypeIP) Value(defaultValue net.IP) net.IP {
40
-	if c.value == nil {
41
-		return defaultValue
39
+func (t TypeIP) String() string {
40
+	if len(t.Value) == 0 {
41
+		return ""
42 42
 	}
43 43
 
44
-	return c.value
44
+	return t.Value.String()
45 45
 }

+ 33
- 44
internal/config/type_ip_test.go Zobrazit soubor

@@ -20,10 +20,11 @@ type TypeIPTestSuite struct {
20 20
 
21 21
 func (suite *TypeIPTestSuite) TestUnmarshalFail() {
22 22
 	testData := []string{
23
-		"0.0.10",
24
-		"10.0.0.10:",
25
-		"xxx:80",
26
-		"2001:0db8:85a3:0000:0000:8a2e:4",
23
+		"",
24
+		"....",
25
+		"0...",
26
+		"300.200.200.800",
27
+		"[]",
27 28
 	}
28 29
 
29 30
 	for _, v := range testData {
@@ -39,74 +40,62 @@ func (suite *TypeIPTestSuite) TestUnmarshalFail() {
39 40
 }
40 41
 
41 42
 func (suite *TypeIPTestSuite) TestUnmarshalOk() {
42
-	testData := []string{
43
-		"0.0.0.0",
44
-		"10.0.0.10",
45
-		"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
43
+	testData := map[string]string{
44
+		"2001:0db8:85a3:0000:0000:8a2e:0370:7334": "2001:db8:85a3::8a2e:370:7334",
45
+		"127.0.0.1": "127.0.0.1",
46 46
 	}
47 47
 
48
-	for _, v := range testData {
49
-		value := v
48
+	for k, v := range testData {
49
+		expected := v
50 50
 
51 51
 		data, err := json.Marshal(map[string]string{
52
-			"value": v,
52
+			"value": k,
53 53
 		})
54 54
 		suite.NoError(err)
55 55
 
56
-		suite.T().Run(v, func(t *testing.T) {
56
+		suite.T().Run(k, func(t *testing.T) {
57 57
 			testStruct := &typeIPTestStruct{}
58
-
59 58
 			assert.NoError(t, json.Unmarshal(data, testStruct))
60
-			assert.Equal(t,
61
-				net.ParseIP(value).String(),
62
-				testStruct.Value.Value(nil).String())
59
+			assert.Equal(t, expected, testStruct.Value.Get(nil).String())
63 60
 		})
64 61
 	}
65 62
 }
66 63
 
67 64
 func (suite *TypeIPTestSuite) TestMarshalOk() {
68 65
 	testData := []string{
69
-		"0.0.0.0",
70
-		"10.0.0.10",
71
-		"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
66
+		"2001:db8:85a3::8a2e:370:7334",
67
+		"127.0.0.1",
72 68
 	}
73 69
 
74 70
 	for _, v := range testData {
75
-		value := net.ParseIP(v).String()
76
-
77
-		data, err := json.Marshal(map[string]string{
78
-			"value": v,
79
-		})
80
-		suite.NoError(err)
71
+		value := v
81 72
 
82 73
 		suite.T().Run(v, func(t *testing.T) {
83
-			testStruct := &typeIPTestStruct{}
74
+			testStruct := &typeIPTestStruct{
75
+				Value: config.TypeIP{
76
+					Value: net.ParseIP(value),
77
+				},
78
+			}
84 79
 
85
-			assert.NoError(t, json.Unmarshal(data, testStruct))
86
-			assert.Equal(t, value, testStruct.Value.String())
80
+			encodedJSON, err := json.Marshal(testStruct)
81
+			assert.NoError(t, err)
87 82
 
88
-			marshalled, err := testStruct.Value.MarshalText()
83
+			expectedJSON, err := json.Marshal(map[string]string{
84
+				"value": value,
85
+			})
89 86
 			assert.NoError(t, err)
90
-			assert.Equal(t, value, string(marshalled))
87
+
88
+			assert.JSONEq(t, string(expectedJSON), string(encodedJSON))
91 89
 		})
92 90
 	}
93 91
 }
94 92
 
95
-func (suite *TypeIPTestSuite) TestValue() {
96
-	testStruct := &typeIPTestStruct{}
97
-	suite.Empty(testStruct.Value.String())
98
-
99
-	suite.Nil(testStruct.Value.Value(nil))
100
-	suite.Equal("127.1.0.1", testStruct.Value.Value(net.ParseIP("127.1.0.1")).String())
101
-
102
-	data, err := json.Marshal(map[string]string{
103
-		"value": "127.0.0.1",
104
-	})
105
-	suite.NoError(err)
106
-	suite.NoError(json.Unmarshal(data, testStruct))
93
+func (suite *TypeIPTestSuite) TestGet() {
94
+	value := config.TypeIP{}
95
+	suite.Equal("127.0.0.1", value.Get(net.ParseIP("127.0.0.1")).String())
107 96
 
108
-	suite.Equal("127.0.0.1", testStruct.Value.Value(nil).String())
109
-	suite.Equal("127.0.0.1", testStruct.Value.Value(net.ParseIP("10.0.0.10")).String())
97
+	suite.NoError(value.Set("127.0.0.2"))
98
+	suite.Equal("127.0.0.2", value.Get(net.ParseIP("127.0.0.1")).String())
110 99
 }
111 100
 
112 101
 func TestTypeIP(t *testing.T) {

+ 18
- 19
internal/config/type_metric_prefix.go Zobrazit soubor

@@ -6,36 +6,35 @@ import (
6 6
 )
7 7
 
8 8
 type TypeMetricPrefix struct {
9
-	value string
9
+	Value string
10 10
 }
11 11
 
12
-func (c *TypeMetricPrefix) UnmarshalText(data []byte) error {
13
-	if len(data) == 0 {
14
-		return nil
12
+func (t *TypeMetricPrefix) Set(value string) error {
13
+	if ok, err := regexp.MatchString("^[a-z0-9]+$", value); !ok || err != nil {
14
+		return fmt.Errorf("incorrect metric prefix %s: %w", value, err)
15 15
 	}
16 16
 
17
-	prefix := string(data)
18
-	if ok, err := regexp.MatchString("^[a-z0-9]+$", prefix); !ok || err != nil {
19
-		return fmt.Errorf("incorrect metric prefix: %s", prefix)
20
-	}
21
-
22
-	c.value = prefix
17
+	t.Value = value
23 18
 
24 19
 	return nil
25 20
 }
26 21
 
27
-func (c TypeMetricPrefix) MarshalText() ([]byte, error) {
28
-	return []byte(c.String()), nil
22
+func (t TypeMetricPrefix) Get(defaultValue string) string {
23
+	if t.Value == "" {
24
+		return defaultValue
25
+	}
26
+
27
+	return t.Value
29 28
 }
30 29
 
31
-func (c TypeMetricPrefix) String() string {
32
-	return c.value
30
+func (t *TypeMetricPrefix) UnmarshalText(data []byte) error {
31
+	return t.Set(string(data))
33 32
 }
34 33
 
35
-func (c TypeMetricPrefix) Value(defaultValue string) string {
36
-	if c.value == "" {
37
-		return defaultValue
38
-	}
34
+func (t TypeMetricPrefix) MarshalText() ([]byte, error) {
35
+	return []byte(t.String()), nil
36
+}
39 37
 
40
-	return c.value
38
+func (t TypeMetricPrefix) String() string {
39
+	return t.Value
41 40
 }

+ 20
- 65
internal/config/type_metric_prefix_test.go Zobrazit soubor

@@ -17,18 +17,13 @@ type TypeMetricPrefixTestSuite struct {
17 17
 	suite.Suite
18 18
 }
19 19
 
20
-func (suite *TypeMetricPrefixTestSuite) TestUnmarshalNil() {
21
-	typ := &config.TypeMetricPrefix{}
22
-	suite.NoError(typ.UnmarshalText(nil))
23
-	suite.Empty(typ.String())
24
-}
25
-
26 20
 func (suite *TypeMetricPrefixTestSuite) TestUnmarshalFail() {
27 21
 	testData := []string{
28
-		"aaa.aaa",
29
-		"aaa-bbb",
30
-		"aaa:ccc",
31
-		"metric prefix",
22
+		"",
23
+		"-",
24
+		"hello/world",
25
+		"lala*",
26
+		"++sdf++",
32 27
 	}
33 28
 
34 29
 	for _, v := range testData {
@@ -44,69 +39,29 @@ func (suite *TypeMetricPrefixTestSuite) TestUnmarshalFail() {
44 39
 }
45 40
 
46 41
 func (suite *TypeMetricPrefixTestSuite) TestUnmarshalOk() {
47
-	testData := []string{
48
-		"mtg",
49
-		"mtg111",
50
-	}
51
-
52
-	for _, v := range testData {
53
-		value := v
54
-
55
-		data, err := json.Marshal(map[string]string{
56
-			"value": v,
57
-		})
58
-		suite.NoError(err)
59
-
60
-		suite.T().Run(v, func(t *testing.T) {
61
-			testStruct := &typeMetricPrefixTestStruct{}
62
-
63
-			assert.NoError(t, json.Unmarshal(data, testStruct))
64
-			assert.Equal(t, value, testStruct.Value.Value(""))
65
-		})
66
-	}
42
+	testStruct := &typeMetricPrefixTestStruct{}
43
+	suite.NoError(json.Unmarshal([]byte(`{"value": "mtg"}`), testStruct))
44
+	suite.Equal("mtg", testStruct.Value.Get("lalala"))
67 45
 }
68 46
 
69 47
 func (suite *TypeMetricPrefixTestSuite) TestMarshalOk() {
70
-	testData := []string{
71
-		"mtg",
72
-		"mtg111",
48
+	testStruct := &typeMetricPrefixTestStruct{
49
+		Value: config.TypeMetricPrefix{
50
+			Value: "mtg",
51
+		},
73 52
 	}
74 53
 
75
-	for _, v := range testData {
76
-		value := v
77
-
78
-		data, err := json.Marshal(map[string]string{
79
-			"value": v,
80
-		})
81
-		suite.NoError(err)
82
-
83
-		suite.T().Run(v, func(t *testing.T) {
84
-			testStruct := &typeMetricPrefixTestStruct{}
85
-
86
-			assert.NoError(t, json.Unmarshal(data, testStruct))
87
-			assert.Equal(t, value, testStruct.Value.String())
88
-
89
-			marshalled, err := testStruct.Value.MarshalText()
90
-			assert.NoError(t, err)
91
-			assert.Equal(t, value, string(marshalled))
92
-		})
93
-	}
54
+	data, err := json.Marshal(testStruct)
55
+	suite.NoError(err)
56
+	suite.JSONEq(`{"value": "mtg"}`, string(data))
94 57
 }
95 58
 
96
-func (suite *TypeMetricPrefixTestSuite) TestValue() {
97
-	testStruct := &typeMetricPrefixTestStruct{}
98
-
99
-	suite.Equal("mtg", testStruct.Value.Value("mtg"))
100
-	suite.Equal("vvv", testStruct.Value.Value("vvv"))
101
-
102
-	data, err := json.Marshal(map[string]string{
103
-		"value": "aaa",
104
-	})
105
-	suite.NoError(err)
106
-	suite.NoError(json.Unmarshal(data, testStruct))
59
+func (suite *TypeMetricPrefixTestSuite) TestGet() {
60
+	value := config.TypeMetricPrefix{}
61
+	suite.Equal("lalala", value.Get("lalala"))
107 62
 
108
-	suite.Equal("aaa", testStruct.Value.Value("mtg"))
109
-	suite.Equal("aaa", testStruct.Value.Value("vvv"))
63
+	value.Value = "mtg"
64
+	suite.Equal("mtg", value.Get("lalala"))
110 65
 }
111 66
 
112 67
 func TestTypeMetricPrefix(t *testing.T) {

+ 20
- 20
internal/config/type_port.go Zobrazit soubor

@@ -6,40 +6,40 @@ import (
6 6
 )
7 7
 
8 8
 type TypePort struct {
9
-	value uint
9
+	Value uint
10 10
 }
11 11
 
12
-func (c *TypePort) UnmarshalJSON(data []byte) error {
13
-	if len(data) == 0 {
14
-		return nil
15
-	}
16
-
17
-	intValue, err := strconv.ParseUint(string(data), 10, 64)
12
+func (t *TypePort) Set(value string) error {
13
+	portValue, err := strconv.ParseUint(value, 10, 16) // nolint: gomnd
18 14
 	if err != nil {
19
-		return fmt.Errorf("port number is not a number: %w", err)
15
+		return fmt.Errorf("incorrect port number (%v): %w", value, err)
20 16
 	}
21 17
 
22
-	if intValue == 0 || intValue >= 65536 {
23
-		return fmt.Errorf("port number should be 0 < portNo < 65536: %d", intValue)
18
+	if portValue == 0 {
19
+		return fmt.Errorf("incorrect port number (%s)", value)
24 20
 	}
25 21
 
26
-	c.value = uint(intValue)
22
+	t.Value = uint(portValue)
27 23
 
28 24
 	return nil
29 25
 }
30 26
 
31
-func (c *TypePort) MarshalJSON() ([]byte, error) {
32
-	return []byte(c.String()), nil
27
+func (t TypePort) Get(defaultValue uint) uint {
28
+	if t.Value == 0 {
29
+		return defaultValue
30
+	}
31
+
32
+	return t.Value
33 33
 }
34 34
 
35
-func (c TypePort) String() string {
36
-	return strconv.Itoa(int(c.value))
35
+func (t *TypePort) UnmarshalJSON(data []byte) error {
36
+	return t.Set(string(data))
37 37
 }
38 38
 
39
-func (c TypePort) Value(defaultValue uint) uint {
40
-	if c.value == 0 {
41
-		return defaultValue
42
-	}
39
+func (t TypePort) MarshalJSON() ([]byte, error) {
40
+	return []byte(t.String()), nil
41
+}
43 42
 
44
-	return c.value
43
+func (t TypePort) String() string {
44
+	return strconv.Itoa(int(t.Value))
45 45
 }

+ 24
- 70
internal/config/type_port_test.go Zobrazit soubor

@@ -2,7 +2,6 @@ package config_test
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"strconv"
6 5
 	"testing"
7 6
 
8 7
 	"github.com/9seconds/mtg/v2/internal/config"
@@ -18,97 +17,52 @@ type TypePortTestSuite struct {
18 17
 	suite.Suite
19 18
 }
20 19
 
21
-func (suite *TypePortTestSuite) TestUnmarshalNil() {
22
-	typ := &config.TypePort{}
23
-	suite.NoError(typ.UnmarshalJSON(nil))
24
-	suite.Equal("0", typ.String())
25
-}
26
-
27 20
 func (suite *TypePortTestSuite) TestUnmarshalFail() {
28
-	testData := []int{
29
-		-1,
30
-		1_000_000,
21
+	testData := []string{
22
+		"",
23
+		"port",
24
+		"0",
25
+		"-1",
26
+		"1.5",
27
+		"70000",
31 28
 	}
32 29
 
33 30
 	for _, v := range testData {
34
-		data, err := json.Marshal(map[string]int{
31
+		data, err := json.Marshal(map[string]string{
35 32
 			"value": v,
36 33
 		})
37 34
 		suite.NoError(err)
38 35
 
39
-		suite.T().Run(strconv.Itoa(v), func(t *testing.T) {
36
+		suite.T().Run(v, func(t *testing.T) {
40 37
 			assert.Error(t, json.Unmarshal(data, &typePortTestStruct{}))
41 38
 		})
42 39
 	}
43 40
 }
44 41
 
45 42
 func (suite *TypePortTestSuite) TestUnmarshalOk() {
46
-	testData := []int{
47
-		1,
48
-		1_000,
49
-		65535,
50
-	}
51
-
52
-	for _, v := range testData {
53
-		value := v
54
-
55
-		data, err := json.Marshal(map[string]int{
56
-			"value": v,
57
-		})
58
-		suite.NoError(err)
59
-
60
-		suite.T().Run(strconv.Itoa(v), func(t *testing.T) {
61
-			testStruct := &typePortTestStruct{}
62
-
63
-			assert.NoError(t, json.Unmarshal(data, testStruct))
64
-			assert.EqualValues(t, value, testStruct.Value.Value(0))
65
-		})
66
-	}
43
+	testStruct := &typePortTestStruct{}
44
+	suite.NoError(json.Unmarshal([]byte(`{"value": 5}`), testStruct))
45
+	suite.EqualValues(5, testStruct.Value.Value)
67 46
 }
68 47
 
69 48
 func (suite *TypePortTestSuite) TestMarshalOk() {
70
-	testData := map[string]int{
71
-		"1":     1,
72
-		"1000":  1000,
73
-		"65535": 65535,
49
+	testStruct := &typePortTestStruct{
50
+		Value: config.TypePort{
51
+			Value: 10,
52
+		},
74 53
 	}
75 54
 
76
-	for k, v := range testData {
77
-		name := k
78
-		value := v
79
-
80
-		data, err := json.Marshal(map[string]int{
81
-			"value": value,
82
-		})
83
-		suite.NoError(err)
84
-
85
-		suite.T().Run(name, func(t *testing.T) {
86
-			testStruct := &typePortTestStruct{}
87
-
88
-			assert.NoError(t, json.Unmarshal(data, testStruct))
89
-			assert.Equal(t, name, testStruct.Value.String())
90
-
91
-			marshalled, err := testStruct.Value.MarshalJSON()
92
-			assert.NoError(t, err)
93
-			assert.Equal(t, name, string(marshalled))
94
-		})
95
-	}
55
+	data, err := json.Marshal(testStruct)
56
+	suite.NoError(err)
57
+	suite.JSONEq(`{"value":10}`, string(data))
96 58
 }
97 59
 
98
-func (suite *TypePortTestSuite) TestValue() {
99
-	testStruct := &typePortTestStruct{}
100
-
101
-	suite.EqualValues(0, testStruct.Value.Value(0))
102
-	suite.EqualValues(1, testStruct.Value.Value(1))
103
-
104
-	data, err := json.Marshal(map[string]int{
105
-		"value": 5,
106
-	})
107
-	suite.NoError(err)
108
-	suite.NoError(json.Unmarshal(data, testStruct))
60
+func (suite *TypePortTestSuite) TestGet() {
61
+	value := config.TypePort{}
62
+	suite.EqualValues(10, value.Get(10))
109 63
 
110
-	suite.EqualValues(5, testStruct.Value.Value(0))
111
-	suite.EqualValues(5, testStruct.Value.Value(1))
64
+	value.Value = 100
65
+	suite.EqualValues(100, value.Get(10))
112 66
 }
113 67
 
114 68
 func TestTypePort(t *testing.T) {

+ 35
- 23
internal/config/type_prefer_ip.go Zobrazit soubor

@@ -6,45 +6,57 @@ import (
6 6
 )
7 7
 
8 8
 const (
9
+	// TypePreferIPPreferIPv4 states that you prefer to use IPv4 addresses
10
+	// but IPv6 is also possible.
9 11
 	TypePreferIPPreferIPv4 = "prefer-ipv4"
12
+
13
+	// TypePreferIPPreferIPv6 states that you prefer to use IPv6 addresses
14
+	// but IPv4 is also possible.
10 15
 	TypePreferIPPreferIPv6 = "prefer-ipv6"
11
-	TypePreferOnlyIPv4     = "only-ipv4"
12
-	TypePreferOnlyIPv6     = "only-ipv6"
16
+
17
+	// TypePreferOnlyIPv4 states that you prefer to use IPv4 addresses
18
+	// only.
19
+	TypePreferOnlyIPv4 = "only-ipv4"
20
+
21
+	// TypePreferOnlyIPv6 states that you prefer to use IPv6 addresses
22
+	// only.
23
+	TypePreferOnlyIPv6 = "only-ipv6"
13 24
 )
14 25
 
15 26
 type TypePreferIP struct {
16
-	value string
27
+	Value string
17 28
 }
18 29
 
19
-func (c *TypePreferIP) UnmarshalText(data []byte) error {
20
-	if len(data) == 0 {
21
-		return nil
22
-	}
30
+func (t *TypePreferIP) Set(value string) error {
31
+	value = strings.ToLower(value)
23 32
 
24
-	text := strings.ToLower(string(data))
33
+	switch value {
34
+	case TypePreferIPPreferIPv4, TypePreferIPPreferIPv6,
35
+		TypePreferOnlyIPv4, TypePreferOnlyIPv6:
36
+		t.Value = value
25 37
 
26
-	switch text {
27
-	case TypePreferIPPreferIPv4, TypePreferIPPreferIPv6, TypePreferOnlyIPv4, TypePreferOnlyIPv6:
28
-		c.value = text
38
+		return nil
29 39
 	default:
30
-		return fmt.Errorf("incorrect prefer-ip value: %s", string(data))
40
+		return fmt.Errorf("unsupported ip preference: %s", value)
31 41
 	}
32
-
33
-	return nil
34 42
 }
35 43
 
36
-func (c TypePreferIP) MarshalText() ([]byte, error) {
37
-	return []byte(c.value), nil
44
+func (t *TypePreferIP) Get(defaultValue string) string {
45
+	if t.Value == "" {
46
+		return defaultValue
47
+	}
48
+
49
+	return t.Value
38 50
 }
39 51
 
40
-func (c *TypePreferIP) String() string {
41
-	return c.value
52
+func (t *TypePreferIP) UnmarshalText(data []byte) error {
53
+	return t.Set(string(data))
42 54
 }
43 55
 
44
-func (c *TypePreferIP) Value(defaultValue string) string {
45
-	if c.value == "" {
46
-		return defaultValue
47
-	}
56
+func (t TypePreferIP) MarshalText() ([]byte, error) {
57
+	return []byte(t.String()), nil
58
+}
48 59
 
49
-	return c.value
60
+func (t TypePreferIP) String() string {
61
+	return t.Value
50 62
 }

+ 28
- 57
internal/config/type_prefer_ip_test.go Zobrazit soubor

@@ -18,18 +18,12 @@ type TypePreferIPTestSuite struct {
18 18
 	suite.Suite
19 19
 }
20 20
 
21
-func (suite *TypePreferIPTestSuite) TestUnmarshalNil() {
22
-	typ := &config.TypePreferIP{}
23
-	suite.NoError(typ.UnmarshalText(nil))
24
-	suite.Empty(typ.String())
25
-}
26
-
27 21
 func (suite *TypePreferIPTestSuite) TestUnmarshalFail() {
28 22
 	testData := []string{
29
-		"p",
30
-		"ipv4",
31
-		"onlyipv4",
32
-		"ipv6prefer",
23
+		"",
24
+		"prefer",
25
+		"preferipv4",
26
+		config.TypePreferIPPreferIPv4 + "_",
33 27
 	}
34 28
 
35 29
 	for _, v := range testData {
@@ -50,14 +44,10 @@ func (suite *TypePreferIPTestSuite) TestUnmarshalOk() {
50 44
 		config.TypePreferIPPreferIPv6,
51 45
 		config.TypePreferOnlyIPv4,
52 46
 		config.TypePreferOnlyIPv6,
53
-		strings.ToUpper(config.TypePreferIPPreferIPv4),
54
-		strings.ToUpper(config.TypePreferIPPreferIPv6),
55
-		strings.ToUpper(config.TypePreferOnlyIPv4),
56
-		strings.ToUpper(config.TypePreferOnlyIPv6),
57
-		strings.ToLower(config.TypePreferIPPreferIPv4),
58
-		strings.ToLower(config.TypePreferIPPreferIPv6),
59
-		strings.ToLower(config.TypePreferOnlyIPv4),
60
-		strings.ToLower(config.TypePreferOnlyIPv6),
47
+		strings.ToTitle(config.TypePreferOnlyIPv4),
48
+		strings.ToTitle(config.TypePreferOnlyIPv6),
49
+		strings.ToTitle(config.TypePreferIPPreferIPv4),
50
+		strings.ToTitle(config.TypePreferIPPreferIPv6),
61 51
 	}
62 52
 
63 53
 	for _, v := range testData {
@@ -70,11 +60,8 @@ func (suite *TypePreferIPTestSuite) TestUnmarshalOk() {
70 60
 
71 61
 		suite.T().Run(v, func(t *testing.T) {
72 62
 			testStruct := &typePreferIPTestStruct{}
73
-
74 63
 			assert.NoError(t, json.Unmarshal(data, testStruct))
75
-			assert.EqualValues(t,
76
-				strings.ToLower(value),
77
-				testStruct.Value.Value(config.TypePreferIPPreferIPv4))
64
+			assert.Equal(t, strings.ToLower(value), testStruct.Value.Value)
78 65
 		})
79 66
 	}
80 67
 }
@@ -85,55 +72,39 @@ func (suite *TypePreferIPTestSuite) TestMarshalOk() {
85 72
 		config.TypePreferIPPreferIPv6,
86 73
 		config.TypePreferOnlyIPv4,
87 74
 		config.TypePreferOnlyIPv6,
88
-		strings.ToUpper(config.TypePreferIPPreferIPv4),
89
-		strings.ToUpper(config.TypePreferIPPreferIPv6),
90
-		strings.ToUpper(config.TypePreferOnlyIPv4),
91
-		strings.ToUpper(config.TypePreferOnlyIPv6),
92
-		strings.ToLower(config.TypePreferIPPreferIPv4),
93
-		strings.ToLower(config.TypePreferIPPreferIPv6),
94
-		strings.ToLower(config.TypePreferOnlyIPv4),
95
-		strings.ToLower(config.TypePreferOnlyIPv6),
96 75
 	}
97 76
 
98 77
 	for _, v := range testData {
99 78
 		value := v
100 79
 
101
-		data, err := json.Marshal(map[string]string{
102
-			"value": v,
103
-		})
104
-		suite.NoError(err)
105
-
106 80
 		suite.T().Run(v, func(t *testing.T) {
107
-			testStruct := &typePreferIPTestStruct{}
81
+			testStruct := &typePreferIPTestStruct{
82
+				Value: config.TypePreferIP{
83
+					Value: value,
84
+				},
85
+			}
108 86
 
109
-			assert.NoError(t, json.Unmarshal(data, testStruct))
110
-			assert.Equal(t, strings.ToLower(value), testStruct.Value.String())
87
+			encodedJSON, err := json.Marshal(testStruct)
88
+			assert.NoError(t, err)
111 89
 
112
-			marshalled, err := testStruct.Value.MarshalText()
90
+			expectedJSON, err := json.Marshal(map[string]string{
91
+				"value": value,
92
+			})
113 93
 			assert.NoError(t, err)
114
-			assert.Equal(t, strings.ToLower(value), string(marshalled))
94
+
95
+			assert.JSONEq(t, string(expectedJSON), string(encodedJSON))
115 96
 		})
116 97
 	}
117 98
 }
118 99
 
119
-func (suite *TypePreferIPTestSuite) TestValue() {
120
-	testStruct := &typePreferIPTestStruct{}
121
-
122
-	suite.EqualValues(config.TypePreferIPPreferIPv4,
123
-		testStruct.Value.Value(config.TypePreferIPPreferIPv4))
124
-	suite.EqualValues(config.TypePreferIPPreferIPv6,
125
-		testStruct.Value.Value(config.TypePreferIPPreferIPv6))
126
-
127
-	data, err := json.Marshal(map[string]string{
128
-		"value": config.TypePreferOnlyIPv4,
129
-	})
130
-	suite.NoError(err)
131
-	suite.NoError(json.Unmarshal(data, testStruct))
100
+func (suite *TypePreferIPTestSuite) TestGet() {
101
+	value := config.TypePreferIP{}
102
+	suite.Equal(config.TypePreferIPPreferIPv4,
103
+		value.Get(config.TypePreferIPPreferIPv4))
132 104
 
133
-	suite.EqualValues(config.TypePreferOnlyIPv4,
134
-		testStruct.Value.Value(config.TypePreferOnlyIPv6))
135
-	suite.EqualValues(config.TypePreferOnlyIPv4,
136
-		testStruct.Value.Value(config.TypePreferIPPreferIPv6))
105
+	suite.NoError(value.Set(config.TypePreferIPPreferIPv6))
106
+	suite.Equal(config.TypePreferIPPreferIPv6,
107
+		value.Get(config.TypePreferIPPreferIPv4))
137 108
 }
138 109
 
139 110
 func TestTypePreferIP(t *testing.T) {

+ 61
- 0
internal/config/type_proxy_url.go Zobrazit soubor

@@ -0,0 +1,61 @@
1
+package config
2
+
3
+import (
4
+	"fmt"
5
+	"net"
6
+	"net/url"
7
+)
8
+
9
+const typeProxyURLDefaultSOCKS5Port = "1080"
10
+
11
+type TypeProxyURL struct {
12
+	Value *url.URL
13
+}
14
+
15
+func (t *TypeProxyURL) Set(value string) error {
16
+	parsedURL, err := url.Parse(value)
17
+	if err != nil {
18
+		return fmt.Errorf("value is not corect URL (%s): %w", value, err)
19
+	}
20
+
21
+	if parsedURL.Host == "" {
22
+		return fmt.Errorf("url has to have a schema: %s", value)
23
+	}
24
+
25
+	if parsedURL.Scheme != "socks5" {
26
+		return fmt.Errorf("unsupported schema: %s", parsedURL.Scheme)
27
+	}
28
+
29
+	if _, _, err := net.SplitHostPort(parsedURL.Host); err != nil {
30
+		parsedURL.Host = net.JoinHostPort(parsedURL.Host,
31
+			typeProxyURLDefaultSOCKS5Port)
32
+	}
33
+
34
+	t.Value = parsedURL
35
+
36
+	return nil
37
+}
38
+
39
+func (t *TypeProxyURL) Get(defaultValue *url.URL) *url.URL {
40
+	if t.Value == nil {
41
+		return defaultValue
42
+	}
43
+
44
+	return t.Value
45
+}
46
+
47
+func (t *TypeProxyURL) UnmarshalText(data []byte) error {
48
+	return t.Set(string(data))
49
+}
50
+
51
+func (t TypeProxyURL) MarshalText() ([]byte, error) {
52
+	return []byte(t.String()), nil
53
+}
54
+
55
+func (t TypeProxyURL) String() string {
56
+	if t.Value == nil {
57
+		return ""
58
+	}
59
+
60
+	return t.Value.String()
61
+}

+ 96
- 0
internal/config/type_proxy_url_test.go Zobrazit soubor

@@ -0,0 +1,96 @@
1
+package config_test
2
+
3
+import (
4
+	"encoding/json"
5
+	"net/url"
6
+	"testing"
7
+
8
+	"github.com/9seconds/mtg/v2/internal/config"
9
+	"github.com/stretchr/testify/assert"
10
+	"github.com/stretchr/testify/suite"
11
+)
12
+
13
+type typeProxyURLTestStruct struct {
14
+	Value config.TypeProxyURL `json:"value"`
15
+}
16
+
17
+type ProxyURLTestSuite struct {
18
+	suite.Suite
19
+}
20
+
21
+func (suite *ProxyURLTestSuite) TestUnmarshalFail() {
22
+	testData := []string{
23
+		"",
24
+		"socks5://",
25
+		"://lala",
26
+		"/path",
27
+	}
28
+
29
+	for _, v := range testData {
30
+		data, err := json.Marshal(map[string]string{
31
+			"value": v,
32
+		})
33
+		suite.NoError(err)
34
+
35
+		suite.T().Run(v, func(t *testing.T) {
36
+			assert.Error(t, json.Unmarshal(data, &typeProxyURLTestStruct{}))
37
+		})
38
+	}
39
+}
40
+
41
+func (suite *ProxyURLTestSuite) TestUnmarshalOk() {
42
+	testData := map[string]string{
43
+		"socks5://127.0.0.1/?open_threshold=1": "socks5://127.0.0.1:1080/?open_threshold=1",
44
+		"socks5://127.0.0.1:80":                "socks5://127.0.0.1:80",
45
+	}
46
+
47
+	for k, v := range testData {
48
+		value := v
49
+
50
+		data, err := json.Marshal(map[string]string{
51
+			"value": k,
52
+		})
53
+		suite.NoError(err)
54
+
55
+		suite.T().Run(k, func(t *testing.T) {
56
+			testStruct := &typeProxyURLTestStruct{}
57
+			assert.NoError(t, json.Unmarshal(data, testStruct))
58
+
59
+			parsed, _ := url.Parse(value)
60
+
61
+			assert.Equal(t, parsed.Scheme, testStruct.Value.Get(nil).Scheme)
62
+			assert.Equal(t, parsed.Host, testStruct.Value.Get(nil).Host)
63
+			assert.Equal(t, parsed.RawQuery, testStruct.Value.Get(nil).RawQuery)
64
+			assert.Equal(t, parsed.Path, testStruct.Value.Get(nil).Path)
65
+		})
66
+	}
67
+}
68
+
69
+func (suite *ProxyURLTestSuite) TestMarshalOk() {
70
+	parsed, _ := url.Parse("socks5://127.0.0.1:1080?open_threshold=1")
71
+	testStruct := &typeProxyURLTestStruct{
72
+		Value: config.TypeProxyURL{
73
+			Value: parsed,
74
+		},
75
+	}
76
+
77
+	encodedJSON, err := json.Marshal(testStruct)
78
+	suite.NoError(err)
79
+	suite.JSONEq(`{"value": "socks5://127.0.0.1:1080?open_threshold=1"}`,
80
+		string(encodedJSON))
81
+}
82
+
83
+func (suite *ProxyURLTestSuite) TestGet() {
84
+	emptyURL := &url.URL{}
85
+
86
+	value := config.TypeProxyURL{}
87
+	suite.Equal(emptyURL, value.Get(emptyURL))
88
+
89
+	value.Value = &url.URL{}
90
+	suite.Equal(value.Value, value.Get(emptyURL))
91
+}
92
+
93
+func TestTypeProxyURL(t *testing.T) {
94
+	t.Parallel()
95
+	suite.Run(t, &ProxyURLTestSuite{})
96
+}

+ 31
- 22
internal/config/type_statsd_tag_format.go Zobrazit soubor

@@ -6,44 +6,53 @@ import (
6 6
 )
7 7
 
8 8
 const (
9
+	// TypeStatsdTagFormatInfluxdb defines a tag format compatible with
10
+	// InfluxDB.
9 11
 	TypeStatsdTagFormatInfluxdb = "influxdb"
10
-	TypeStatsdTagFormatDatadog  = "datadog"
12
+
13
+	// TypeStatsdTagFormatDatadog defines a tag format compatible with
14
+	// DataDog.
15
+	TypeStatsdTagFormatDatadog = "datadog"
16
+
17
+	// TypeStatsdTagFormatGraphite defines a tag format compatible with
18
+	// Graphite.
11 19
 	TypeStatsdTagFormatGraphite = "graphite"
12 20
 )
13 21
 
14 22
 type TypeStatsdTagFormat struct {
15
-	value string
23
+	Value string
16 24
 }
17 25
 
18
-func (c *TypeStatsdTagFormat) UnmarshalText(data []byte) error {
19
-	if len(data) == 0 {
20
-		return nil
21
-	}
26
+func (t *TypeStatsdTagFormat) Set(value string) error {
27
+	lowercasedValue := strings.ToLower(value)
22 28
 
23
-	text := strings.ToLower(string(data))
29
+	switch lowercasedValue {
30
+	case TypeStatsdTagFormatDatadog, TypeStatsdTagFormatInfluxdb,
31
+		TypeStatsdTagFormatGraphite:
32
+		t.Value = lowercasedValue
24 33
 
25
-	switch text {
26
-	case TypeStatsdTagFormatInfluxdb, TypeStatsdTagFormatDatadog, TypeStatsdTagFormatGraphite:
27
-		c.value = text
34
+		return nil
28 35
 	default:
29
-		return fmt.Errorf("incorrect tag format value: %s", string(data))
36
+		return fmt.Errorf("unknown tag format %s", value)
30 37
 	}
31
-
32
-	return nil
33 38
 }
34 39
 
35
-func (c TypeStatsdTagFormat) MarshalText() ([]byte, error) {
36
-	return []byte(c.value), nil
40
+func (t TypeStatsdTagFormat) Get(defaultValue string) string {
41
+	if t.Value == "" {
42
+		return defaultValue
43
+	}
44
+
45
+	return t.Value
37 46
 }
38 47
 
39
-func (c *TypeStatsdTagFormat) String() string {
40
-	return c.value
48
+func (t *TypeStatsdTagFormat) UnmarshalText(data []byte) error {
49
+	return t.Set(string(data))
41 50
 }
42 51
 
43
-func (c *TypeStatsdTagFormat) Value(defaultValue string) string {
44
-	if c.value == "" {
45
-		return defaultValue
46
-	}
52
+func (t *TypeStatsdTagFormat) MarshalText() ([]byte, error) {
53
+	return []byte(t.String()), nil
54
+}
47 55
 
48
-	return c.value
56
+func (t *TypeStatsdTagFormat) String() string {
57
+	return t.Value
49 58
 }

+ 30
- 58
internal/config/type_statsd_tag_format_test.go Zobrazit soubor

@@ -14,22 +14,14 @@ type typeStatsdTagFormatTestStruct struct {
14 14
 	Value config.TypeStatsdTagFormat `json:"value"`
15 15
 }
16 16
 
17
-type TypeStatsdTagFormatTestSuite struct {
17
+type StatsdTagFormatTestSuite struct {
18 18
 	suite.Suite
19 19
 }
20 20
 
21
-func (suite *TypeStatsdTagFormatTestSuite) TestUnmarshalNil() {
22
-	typ := &config.TypeStatsdTagFormat{}
23
-	suite.NoError(typ.UnmarshalText(nil))
24
-	suite.Equal("lalala", typ.Value("lalala"))
25
-}
26
-
27
-func (suite *TypeStatsdTagFormatTestSuite) TestUnmarshalFail() {
21
+func (suite *StatsdTagFormatTestSuite) TestUnmarshalFail() {
28 22
 	testData := []string{
29
-		"p",
30
-		"ipv4",
31
-		"onlyipv4",
32
-		"ipv6prefer",
23
+		"",
24
+		"dogdog",
33 25
 	}
34 26
 
35 27
 	for _, v := range testData {
@@ -44,17 +36,14 @@ func (suite *TypeStatsdTagFormatTestSuite) TestUnmarshalFail() {
44 36
 	}
45 37
 }
46 38
 
47
-func (suite *TypeStatsdTagFormatTestSuite) TestUnmarshalOk() {
39
+func (suite *StatsdTagFormatTestSuite) TestUnmarshalOk() {
48 40
 	testData := []string{
49
-		config.TypeStatsdTagFormatDatadog,
50 41
 		config.TypeStatsdTagFormatInfluxdb,
51 42
 		config.TypeStatsdTagFormatGraphite,
52
-		strings.ToUpper(config.TypeStatsdTagFormatDatadog),
43
+		config.TypeStatsdTagFormatDatadog,
53 44
 		strings.ToUpper(config.TypeStatsdTagFormatInfluxdb),
54 45
 		strings.ToUpper(config.TypeStatsdTagFormatGraphite),
55
-		strings.ToLower(config.TypeStatsdTagFormatDatadog),
56
-		strings.ToLower(config.TypeStatsdTagFormatInfluxdb),
57
-		strings.ToLower(config.TypeStatsdTagFormatGraphite),
46
+		strings.ToUpper(config.TypeStatsdTagFormatDatadog),
58 47
 	}
59 48
 
60 49
 	for _, v := range testData {
@@ -67,70 +56,53 @@ func (suite *TypeStatsdTagFormatTestSuite) TestUnmarshalOk() {
67 56
 
68 57
 		suite.T().Run(v, func(t *testing.T) {
69 58
 			testStruct := &typeStatsdTagFormatTestStruct{}
70
-
71 59
 			assert.NoError(t, json.Unmarshal(data, testStruct))
72
-			assert.EqualValues(t,
73
-				strings.ToLower(value),
74
-				testStruct.Value.Value(config.TypeStatsdTagFormatDatadog))
60
+			assert.Equal(t, strings.ToLower(value), testStruct.Value.Value)
75 61
 		})
76 62
 	}
77 63
 }
78 64
 
79
-func (suite *TypeStatsdTagFormatTestSuite) TestMarshalOk() {
65
+func (suite *StatsdTagFormatTestSuite) TestMarshalOk() {
80 66
 	testData := []string{
81
-		config.TypeStatsdTagFormatDatadog,
82 67
 		config.TypeStatsdTagFormatInfluxdb,
83 68
 		config.TypeStatsdTagFormatGraphite,
84
-		strings.ToUpper(config.TypeStatsdTagFormatDatadog),
85
-		strings.ToUpper(config.TypeStatsdTagFormatInfluxdb),
86
-		strings.ToUpper(config.TypeStatsdTagFormatGraphite),
87
-		strings.ToLower(config.TypeStatsdTagFormatDatadog),
88
-		strings.ToLower(config.TypeStatsdTagFormatInfluxdb),
89
-		strings.ToLower(config.TypeStatsdTagFormatGraphite),
69
+		config.TypeStatsdTagFormatDatadog,
90 70
 	}
91 71
 
92 72
 	for _, v := range testData {
93 73
 		value := v
94 74
 
95
-		data, err := json.Marshal(map[string]string{
96
-			"value": v,
97
-		})
98
-		suite.NoError(err)
99
-
100 75
 		suite.T().Run(v, func(t *testing.T) {
101
-			testStruct := &typeStatsdTagFormatTestStruct{}
76
+			testStruct := &typeStatsdTagFormatTestStruct{
77
+				Value: config.TypeStatsdTagFormat{
78
+					Value: value,
79
+				},
80
+			}
102 81
 
103
-			assert.NoError(t, json.Unmarshal(data, testStruct))
104
-			assert.Equal(t, strings.ToLower(value), testStruct.Value.String())
82
+			encodedJSON, err := json.Marshal(testStruct)
83
+			assert.NoError(t, err)
105 84
 
106
-			marshalled, err := testStruct.Value.MarshalText()
85
+			expectedJSON, err := json.Marshal(map[string]string{
86
+				"value": value,
87
+			})
107 88
 			assert.NoError(t, err)
108
-			assert.Equal(t, strings.ToLower(value), string(marshalled))
89
+
90
+			assert.JSONEq(t, string(expectedJSON), string(encodedJSON))
109 91
 		})
110 92
 	}
111 93
 }
112 94
 
113
-func (suite *TypeStatsdTagFormatTestSuite) TestValue() {
114
-	testStruct := &typePreferIPTestStruct{}
115
-
116
-	suite.EqualValues(config.TypePreferIPPreferIPv4,
117
-		testStruct.Value.Value(config.TypePreferIPPreferIPv4))
118
-	suite.EqualValues(config.TypePreferIPPreferIPv6,
119
-		testStruct.Value.Value(config.TypePreferIPPreferIPv6))
120
-
121
-	data, err := json.Marshal(map[string]string{
122
-		"value": config.TypePreferOnlyIPv4,
123
-	})
124
-	suite.NoError(err)
125
-	suite.NoError(json.Unmarshal(data, testStruct))
95
+func (suite *StatsdTagFormatTestSuite) TestGet() {
96
+	value := config.TypeStatsdTagFormat{}
97
+	suite.Equal(config.TypeStatsdTagFormatDatadog,
98
+		value.Get(config.TypeStatsdTagFormatDatadog))
126 99
 
127
-	suite.EqualValues(config.TypePreferOnlyIPv4,
128
-		testStruct.Value.Value(config.TypePreferOnlyIPv6))
129
-	suite.EqualValues(config.TypePreferOnlyIPv4,
130
-		testStruct.Value.Value(config.TypePreferIPPreferIPv6))
100
+	suite.NoError(value.Set(config.TypeStatsdTagFormatInfluxdb))
101
+	suite.Equal(config.TypeStatsdTagFormatInfluxdb,
102
+		value.Get(config.TypeStatsdTagFormatDatadog))
131 103
 }
132 104
 
133 105
 func TestTypeStatsdTagFormat(t *testing.T) {
134 106
 	t.Parallel()
135
-	suite.Run(t, &TypeStatsdTagFormatTestSuite{})
107
+	suite.Run(t, &StatsdTagFormatTestSuite{})
136 108
 }

+ 0
- 71
internal/config/type_url.go Zobrazit soubor

@@ -1,71 +0,0 @@
1
-package config
2
-
3
-import (
4
-	"fmt"
5
-	"net"
6
-	"net/url"
7
-)
8
-
9
-type TypeURL struct {
10
-	value *url.URL
11
-}
12
-
13
-func (c *TypeURL) UnmarshalText(data []byte) error { // nolint: cyclop
14
-	if len(data) == 0 {
15
-		return nil
16
-	}
17
-
18
-	value, err := url.Parse(string(data))
19
-	if err != nil {
20
-		return fmt.Errorf("incorrect URL: %w", err)
21
-	}
22
-
23
-	switch value.Scheme {
24
-	case "http", "https", "socks5":
25
-	case "":
26
-		return fmt.Errorf("url %s has to have a schema", value)
27
-	default:
28
-		return fmt.Errorf("unsupported schema %s", value.Scheme)
29
-	}
30
-
31
-	if value.Host == "" {
32
-		return fmt.Errorf("url %s has to have a host", value)
33
-	}
34
-
35
-	if _, _, err := net.SplitHostPort(value.Host); err != nil {
36
-		switch value.Scheme {
37
-		case "http":
38
-			value.Host = net.JoinHostPort(value.Host, "80")
39
-		case "https":
40
-			value.Host = net.JoinHostPort(value.Host, "443")
41
-		case "socks5":
42
-			value.Host = net.JoinHostPort(value.Host, "1080")
43
-		default:
44
-			return fmt.Errorf("cannot set a default port for %s", value)
45
-		}
46
-	}
47
-
48
-	c.value = value
49
-
50
-	return nil
51
-}
52
-
53
-func (c *TypeURL) MarshalText() ([]byte, error) {
54
-	return []byte(c.String()), nil
55
-}
56
-
57
-func (c TypeURL) String() string {
58
-	if c.value == nil {
59
-		return ""
60
-	}
61
-
62
-	return c.value.String()
63
-}
64
-
65
-func (c TypeURL) Value(defaultValue *url.URL) *url.URL {
66
-	if c.value == nil {
67
-		return defaultValue
68
-	}
69
-
70
-	return c.value
71
-}

+ 0
- 107
internal/config/type_url_test.go Zobrazit soubor

@@ -1,107 +0,0 @@
1
-package config_test
2
-
3
-import (
4
-	"encoding/json"
5
-	"net/url"
6
-	"testing"
7
-
8
-	"github.com/9seconds/mtg/v2/internal/config"
9
-	"github.com/stretchr/testify/assert"
10
-	"github.com/stretchr/testify/suite"
11
-)
12
-
13
-type typeURLTestStruct struct {
14
-	Value config.TypeURL `json:"value"`
15
-}
16
-
17
-type TypeURLTestSuite struct {
18
-	suite.Suite
19
-}
20
-
21
-func (suite *TypeURLTestSuite) TestUnmarshalNil() {
22
-	u, _ := url.Parse("https://google.com")
23
-
24
-	typ := &config.TypeURL{}
25
-	suite.NoError(typ.UnmarshalText(nil))
26
-	suite.Empty(typ.String())
27
-	suite.Equal("https://google.com", typ.Value(u).String())
28
-}
29
-
30
-func (suite *TypeURLTestSuite) TestUnmarshalFail() {
31
-	testData := []string{
32
-		"http:/aaa.com",
33
-		"ipv4",
34
-		"111",
35
-		"://111",
36
-		"http://aaa.com:xxx",
37
-		"gopher://aaa.com:888",
38
-		"gopher://aaa.com",
39
-	}
40
-
41
-	for _, v := range testData {
42
-		data, err := json.Marshal(map[string]string{
43
-			"value": v,
44
-		})
45
-		suite.NoError(err)
46
-
47
-		suite.T().Run(v, func(t *testing.T) {
48
-			assert.Error(t, json.Unmarshal(data, &typeURLTestStruct{}))
49
-		})
50
-	}
51
-}
52
-
53
-func (suite *TypeURLTestSuite) TestUnmarshalOk() {
54
-	testData := map[string]string{
55
-		"https://10.0.0.10:80":    "https://10.0.0.10:80",
56
-		"https://10.0.0.10:443":   "https://10.0.0.10",
57
-		"http://10.0.0.10:8":      "http://10.0.0.10:8",
58
-		"http://10.0.0.10:80":     "http://10.0.0.10",
59
-		"socks5://10.0.0.10:1080": "socks5://10.0.0.10",
60
-		"socks5://10.0.0.10:888":  "socks5://10.0.0.10:888",
61
-	}
62
-
63
-	for k, v := range testData {
64
-		expected := k
65
-		actual := v
66
-
67
-		data, err := json.Marshal(map[string]string{
68
-			"value": actual,
69
-		})
70
-		suite.NoError(err)
71
-
72
-		suite.T().Run(actual, func(t *testing.T) {
73
-			testStruct := &typeURLTestStruct{}
74
-
75
-			assert.NoError(t, json.Unmarshal(data, testStruct))
76
-			assert.Equal(t, expected, testStruct.Value.Value(nil).String())
77
-
78
-			marshalled, err := testStruct.Value.MarshalText()
79
-			assert.NoError(t, err)
80
-			assert.Equal(t, expected, string(marshalled))
81
-		})
82
-	}
83
-}
84
-
85
-func (suite *TypeURLTestSuite) TestValue() {
86
-	testStruct := &typeURLTestStruct{}
87
-
88
-	u1, _ := url.Parse("https://10.0.0.10:80")
89
-	u2, _ := url.Parse("https://10.1.0.10:80")
90
-
91
-	suite.Equal("https://10.0.0.10:80", testStruct.Value.Value(u1).String())
92
-	suite.Equal("https://10.1.0.10:80", testStruct.Value.Value(u2).String())
93
-
94
-	data, err := json.Marshal(map[string]string{
95
-		"value": "http://127.0.0.1:80",
96
-	})
97
-	suite.NoError(err)
98
-	suite.NoError(json.Unmarshal(data, testStruct))
99
-
100
-	suite.Equal("http://127.0.0.1:80", testStruct.Value.Value(u1).String())
101
-	suite.Equal("http://127.0.0.1:80", testStruct.Value.Value(u2).String())
102
-}
103
-
104
-func TestTypeURL(t *testing.T) {
105
-	t.Parallel()
106
-	suite.Run(t, &TypeURLTestSuite{})
107
-}

+ 19
- 0
internal/utils/make_qr_code_url.go Zobrazit soubor

@@ -0,0 +1,19 @@
1
+package utils
2
+
3
+import "net/url"
4
+
5
+func MakeQRCodeURL(data string) string {
6
+	values := url.Values{}
7
+	values.Set("qzone", "4")
8
+	values.Set("format", "svg")
9
+	values.Set("data", data)
10
+
11
+	rv := url.URL{
12
+		Scheme:   "https",
13
+		Host:     "api.qrserver.com",
14
+		Path:     "/v1/create-qr-code",
15
+		RawQuery: values.Encode(),
16
+	}
17
+
18
+	return rv.String()
19
+}

+ 31
- 0
internal/utils/make_qr_code_url_test.go Zobrazit soubor

@@ -0,0 +1,31 @@
1
+package utils_test
2
+
3
+import (
4
+	"net/url"
5
+	"strings"
6
+	"testing"
7
+
8
+	"github.com/9seconds/mtg/v2/internal/utils"
9
+	"github.com/stretchr/testify/suite"
10
+)
11
+
12
+type MakeQRCodeURLTestSuite struct {
13
+	suite.Suite
14
+}
15
+
16
+func (suite *MakeQRCodeURLTestSuite) TestSomeData() {
17
+	value := utils.MakeQRCodeURL("some data")
18
+
19
+	parsed, err := url.Parse(value)
20
+	suite.NoError(err)
21
+
22
+	suite.Equal("some data", parsed.Query().Get("data"))
23
+	suite.Equal("svg", parsed.Query().Get("format"))
24
+	suite.Equal("api.qrserver.com", strings.TrimPrefix(parsed.Host, "www."))
25
+	suite.Equal("v1/create-qr-code", strings.Trim(parsed.Path, "/"))
26
+}
27
+
28
+func TestMakeQRCodeURL(t *testing.T) {
29
+	t.Parallel()
30
+	suite.Run(t, &MakeQRCodeURLTestSuite{})
31
+}

+ 26
- 0
internal/utils/read_config.go Zobrazit soubor

@@ -0,0 +1,26 @@
1
+package utils
2
+
3
+import (
4
+	"fmt"
5
+	"os"
6
+
7
+	"github.com/9seconds/mtg/v2/internal/config"
8
+)
9
+
10
+func ReadConfig(path string) (*config.Config, error) {
11
+	content, err := os.ReadFile(path)
12
+	if err != nil {
13
+		return nil, fmt.Errorf("cannot read config file: %w", err)
14
+	}
15
+
16
+	conf, err := config.Parse(content)
17
+	if err != nil {
18
+		return nil, fmt.Errorf("cannot parse config: %w", err)
19
+	}
20
+
21
+	if err := conf.Validate(); err != nil {
22
+		return nil, fmt.Errorf("invalid config: %w", err)
23
+	}
24
+
25
+	return conf, nil
26
+}

+ 55
- 0
internal/utils/read_config_test.go Zobrazit soubor

@@ -0,0 +1,55 @@
1
+package utils_test
2
+
3
+import (
4
+	"path/filepath"
5
+	"testing"
6
+
7
+	"github.com/9seconds/mtg/v2/internal/utils"
8
+	"github.com/stretchr/testify/suite"
9
+)
10
+
11
+type ReadConfigTestSuite struct {
12
+	suite.Suite
13
+}
14
+
15
+func (suite *ReadConfigTestSuite) GetConfigPath(filename string) string {
16
+	return filepath.Join("testdata", filename)
17
+}
18
+
19
+func (suite *ReadConfigTestSuite) TestReadMinimal() {
20
+	conf, err := utils.ReadConfig(suite.GetConfigPath("minimal.toml"))
21
+	suite.NoError(err)
22
+	suite.NoError(conf.Validate())
23
+	suite.Equal("0.0.0.0:80", conf.BindTo.Get(""))
24
+	suite.Equal("7mqFMMq3P2Tvvt_rPx5qhmFnb29nbGUuY29t", conf.Secret.Base64())
25
+}
26
+
27
+func (suite *ReadConfigTestSuite) TestReadAbsentFile() {
28
+	_, err := utils.ReadConfig(suite.GetConfigPath("unknown.file"))
29
+	suite.Error(err)
30
+}
31
+
32
+func (suite *ReadConfigTestSuite) TestBrokenFile() {
33
+	_, err := utils.ReadConfig(suite.GetConfigPath("broken.toml"))
34
+	suite.Error(err)
35
+}
36
+
37
+func (suite *ReadConfigTestSuite) TestMissedBindTo() {
38
+	_, err := utils.ReadConfig(suite.GetConfigPath("missed-bindto.toml"))
39
+	suite.Error(err)
40
+}
41
+
42
+func (suite *ReadConfigTestSuite) TestMissedSecret() {
43
+	_, err := utils.ReadConfig(suite.GetConfigPath("missed-secret.toml"))
44
+	suite.Error(err)
45
+}
46
+
47
+func (suite *ReadConfigTestSuite) TestEmpty() {
48
+	_, err := utils.ReadConfig(suite.GetConfigPath("empty.toml"))
49
+	suite.Error(err)
50
+}
51
+
52
+func TestReadConfig(t *testing.T) {
53
+	t.Parallel()
54
+	suite.Run(t, &ReadConfigTestSuite{})
55
+}

+ 1
- 0
internal/utils/testdata/broken.toml Zobrazit soubor

@@ -0,0 +1 @@
1
+11

+ 0
- 0
internal/utils/testdata/empty.toml Zobrazit soubor


internal/cli/testdata/minimal.toml → internal/utils/testdata/minimal.toml Zobrazit soubor


+ 2
- 0
internal/utils/testdata/missed-bindto.toml Zobrazit soubor

@@ -0,0 +1,2 @@
1
+
2
+secret = "7mqFMMq3P2Tvvt_rPx5qhmFnb29nbGUuY29t"

+ 1
- 0
internal/utils/testdata/missed-secret.toml Zobrazit soubor

@@ -0,0 +1 @@
1
+bind-to = "0.0.0.0:80"

+ 2
- 2
ipblocklist/firehol.go Zobrazit soubor

@@ -119,7 +119,7 @@ func (f *Firehol) Run(updateEach time.Duration) {
119 119
 }
120 120
 
121 121
 func (f *Firehol) containsIPv4(addr net.IP) bool {
122
-	ip := patricia.NewIPv4AddressFromBytes(addr, 32)
122
+	ip := patricia.NewIPv4AddressFromBytes(addr, 32) // nolint: gomnd
123 123
 
124 124
 	if ok, _, err := f.treeV4.FindDeepestTag(ip); ok && err == nil {
125 125
 		return true
@@ -129,7 +129,7 @@ func (f *Firehol) containsIPv4(addr net.IP) bool {
129 129
 }
130 130
 
131 131
 func (f *Firehol) containsIPv6(addr net.IP) bool {
132
-	ip := patricia.NewIPv6Address(addr, 128)
132
+	ip := patricia.NewIPv6Address(addr, 128) // nolint: gomnd
133 133
 
134 134
 	if ok, _, err := f.treeV6.FindDeepestTag(ip); ok && err == nil {
135 135
 		return true

+ 2
- 2
mtglib/internal/faketls/client_hello_test.go Zobrazit soubor

@@ -18,9 +18,9 @@ import (
18 18
 type ClientHelloSnapshot struct {
19 19
 	Time        int    `json:"time"`
20 20
 	Random      string `json:"random"`
21
-	SessionID   string `json:"session-id"`
21
+	SessionID   string `json:"sessionId"`
22 22
 	Host        string `json:"host"`
23
-	CipherSuite int    `json:"cipher-suite"`
23
+	CipherSuite int    `json:"cipherSuite"`
24 24
 	Full        string `json:"full"`
25 25
 }
26 26
 

+ 22
- 4
mtglib/internal/faketls/init.go Zobrazit soubor

@@ -6,25 +6,43 @@ import (
6 6
 )
7 7
 
8 8
 const (
9
+	// RandomLen defines a size of the random digest in TLS Hellos.
9 10
 	RandomLen = 32
10 11
 
11
-	ClientHelloRandomOffset    = 6
12
+	// ClientHelloRandomOffset is an offset in ClientHello record where
13
+	// random digest is started.
14
+	ClientHelloRandomOffset = 6
15
+
16
+	// ClientHelloSessionIDOffset is an offset in ClientHello record where
17
+	// SessionID is started.
12 18
 	ClientHelloSessionIDOffset = ClientHelloRandomOffset + RandomLen
13
-	ClientHelloMinLen          = 4
14 19
 
20
+	// ClientHelloMinLen is a minimal possible length of
21
+	// ClientHello record.
22
+	ClientHelloMinLen = 4
23
+
24
+	// WelcomePacketRandomOffset is an offset of random in ServerHello
25
+	// packet (including record envelope).
15 26
 	WelcomePacketRandomOffset = 11
16 27
 
28
+	// HandshakeTypeClient is a value representing a client handshake.
17 29
 	HandshakeTypeClient = 0x01
30
+
31
+	// HandshakeTypeServer is a value representing a server handshake.
18 32
 	HandshakeTypeServer = 0x02
19 33
 
34
+	// ChangeCipherValue is a value representing a change cipher
35
+	// specification record.
20 36
 	ChangeCipherValue = 0x01
21 37
 
38
+	// ExtensionSNI is a value for TLS extension 'SNI'.
22 39
 	ExtensionSNI = 0x00
23 40
 )
24 41
 
25 42
 var (
26
-	ErrBadDigest        = errors.New("bad digest")
27
-	ErrAntiReplayAttack = errors.New("antireplay attack was detected")
43
+	// ErrBadDigest is returned if given TLS Client Hello mismatches with a
44
+	// derived one.
45
+	ErrBadDigest = errors.New("bad digest")
28 46
 
29 47
 	serverHelloSuffix = []byte{
30 48
 		0x00,       // no compression

+ 18
- 2
mtglib/internal/faketls/record/init.go Zobrazit soubor

@@ -7,9 +7,18 @@ const TLSMaxRecordSize = 65535 // max uint16
7 7
 type Type uint8
8 8
 
9 9
 const (
10
+	// TypeChangeCipherSpec defines a byte value of the TLS record when a
11
+	// peer wants to change a specifications of the chosen cipher.
10 12
 	TypeChangeCipherSpec Type = 0x14
11
-	TypeHandshake        Type = 0x16
12
-	TypeApplicationData  Type = 0x17
13
+
14
+	// TypeHandshake defines a byte value of the TLS record when a peer
15
+	// initiates a new TLS connection and wants to make a handshake
16
+	// ceremony.
17
+	TypeHandshake Type = 0x16
18
+
19
+	// TypeApplicationData defines a byte value of the TLS record when a
20
+	// peer sends an user data, not a control frames.
21
+	TypeApplicationData Type = 0x17
13 22
 )
14 23
 
15 24
 func (t Type) String() string {
@@ -37,9 +46,16 @@ func (t Type) Valid() error {
37 46
 type Version uint16
38 47
 
39 48
 const (
49
+	// Version10 defines a TLS1.0.
40 50
 	Version10 Version = 769 // 0x03 0x01
51
+
52
+	// Version11 defines a TLS1.1.
41 53
 	Version11 Version = 770 // 0x03 0x02
54
+
55
+	// Version12 defines a TLS1.2.
42 56
 	Version12 Version = 771 // 0x03 0x03
57
+
58
+	// Version13 defines a TLS1.3.
43 59
 	Version13 Version = 772 // 0x03 0x04
44 60
 )
45 61
 

+ 2
- 2
mtglib/internal/faketls/testdata/client-hello-bad-fa2e46cdb33e2a1b.json Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 {
2 2
   "time": 1617181365,
3 3
   "random": "XvCPc3aAbHbhRLv0kUmy6BfPZOGvsused5/HNsKXEPs=",
4
-  "session-id": "St2BZ2uHMFn3B2trD1jfdtpjoJOOg6JBeLhFcyCMCq4=",
4
+  "sessionId": "St2BZ2uHMFn3B2trD1jfdtpjoJOOg6JBeLhFcyCMCq4=",
5 5
   "host": "storage.googleapis.com",
6
-  "cipher-suite": 4867,
6
+  "cipherSuite": 4867,
7 7
   "full": "AQAB/AMDXvCPc3aAbHbhRLv0kUmy6BfPZOGvsused5/HNsKXEPsgSt2BZ2uHMFn3B2trD1jfdtpjoJOOg6JBeLhFcyCACq4ANBMDEwETAsAswCvAJMAjwArACcypwDDAL8AowCfAFMATzKgAnQCcAD0APAA1AC/ACMASAAoBAAF//wEAAQAAAAAbABkAABZzdG9yYWdlLmdvb2dsZWFwaXMuY29tABcAAAANABgAFgQDCAQEAQUDAgMIBQgFBQEIBgYBAgEABQAFANAAAAAzdAAAABIAAAAQADAALgJoMgVoMi0xNgVoMi0xNQVoMi0xNAhzcGR5LzMuMQZzcGR5LzMIaHR0cC8xLjEACwACAQAAMwAmACQAHQAgB/7oLx9JElIALsLJS91H2QNyU1H0osKwIUelVndsLyIALQACAQEAKwAJCAMEAwMDAgMBAAoACgAIAB0AFwAYABkAFQChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
8 8
 }

+ 3
- 3
mtglib/internal/faketls/testdata/client-hello-ok-19dfe38384b9884b.json Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 {
2 2
   "time": 1617181365,
3 3
   "random": "XvCPc3aAbHbhRLv0kUmy6BfPZOGvsused5/HNsKXEPs=",
4
-  "session-id": "St2BZ2uHMFn3B2trD1jfdtpjoJOOg6JBeLhFcyCMCq4=",
4
+  "sessionId": "St2BZ2uHMFn3B2trD1jfdtpjoJOOg6JBeLhFcyCMCq4=",
5 5
   "host": "storage.googleapis.com",
6
-  "cipher-suite": 4867,
6
+  "cipherSuite": 4867,
7 7
   "full": "AQAB/AMDXvCPc3aAbHbhRLv0kUmy6BfPZOGvsused5/HNsKXEPsgSt2BZ2uHMFn3B2trD1jfdtpjoJOOg6JBeLhFcyCMCq4ANBMDEwETAsAswCvAJMAjwArACcypwDDAL8AowCfAFMATzKgAnQCcAD0APAA1AC/ACMASAAoBAAF//wEAAQAAAAAbABkAABZzdG9yYWdlLmdvb2dsZWFwaXMuY29tABcAAAANABgAFgQDCAQEAQUDAgMIBQgFBQEIBgYBAgEABQAFAQAAAAAzdAAAABIAAAAQADAALgJoMgVoMi0xNgVoMi0xNQVoMi0xNAhzcGR5LzMuMQZzcGR5LzMIaHR0cC8xLjEACwACAQAAMwAmACQAHQAgB/7oLx9JElIALsLJS91H2QNyU1H0osKwIUelVndsLyIALQACAQEAKwAJCAMEAwMDAgMBAAoACgAIAB0AFwAYABkAFQChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
8
-}
8
+}

+ 3
- 3
mtglib/internal/faketls/testdata/client-hello-ok-48f8a72a56f3174a.json Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 {
2 2
   "time": 1617181352,
3 3
   "random": "oYEu33jl+zQbUKMtQbV1OHB0gXIM2y2aq9iY0QX12os=",
4
-  "session-id": "FGqA3ZFYrSlj//xl7lammNn64K9/MK2mQ3HJUGvP+8g=",
4
+  "sessionId": "FGqA3ZFYrSlj//xl7lammNn64K9/MK2mQ3HJUGvP+8g=",
5 5
   "host": "storage.googleapis.com",
6
-  "cipher-suite": 4867,
6
+  "cipherSuite": 4867,
7 7
   "full": "AQAB/AMDoYEu33jl+zQbUKMtQbV1OHB0gXIM2y2aq9iY0QX12osgFGqA3ZFYrSlj//xl7lammNn64K9/MK2mQ3HJUGvP+8gANBMDEwETAsAswCvAJMAjwArACcypwDDAL8AowCfAFMATzKgAnQCcAD0APAA1AC/ACMASAAoBAAF//wEAAQAAAAAbABkAABZzdG9yYWdlLmdvb2dsZWFwaXMuY29tABcAAAANABgAFgQDCAQEAQUDAgMIBQgFBQEIBgYBAgEABQAFAQAAAAAzdAAAABIAAAAQADAALgJoMgVoMi0xNgVoMi0xNQVoMi0xNAhzcGR5LzMuMQZzcGR5LzMIaHR0cC8xLjEACwACAQAAMwAmACQAHQAga6CocpFP8Qd4YCFR9pkaCr97po2ALj0P5nI9Nnb3UWMALQACAQEAKwAJCAMEAwMDAgMBAAoACgAIAB0AFwAYABkAFQChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
8
-}
8
+}

+ 3
- 3
mtglib/internal/faketls/testdata/client-hello-ok-651054256093c6cd.json Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 {
2 2
   "time": 1617181352,
3 3
   "random": "5V5sSprk/tFIgy+x1BeKNGhLlFkqfggLpgN7GYOA1ro=",
4
-  "session-id": "jxr4d6PXPDk+Lwx3WUp9wvj8TGlOxEdrRJ0ydyJ9+H8=",
4
+  "sessionId": "jxr4d6PXPDk+Lwx3WUp9wvj8TGlOxEdrRJ0ydyJ9+H8=",
5 5
   "host": "storage.googleapis.com",
6
-  "cipher-suite": 4867,
6
+  "cipherSuite": 4867,
7 7
   "full": "AQAB/AMD5V5sSprk/tFIgy+x1BeKNGhLlFkqfggLpgN7GYOA1rogjxr4d6PXPDk+Lwx3WUp9wvj8TGlOxEdrRJ0ydyJ9+H8ANBMDEwETAsAswCvAJMAjwArACcypwDDAL8AowCfAFMATzKgAnQCcAD0APAA1AC/ACMASAAoBAAF//wEAAQAAAAAbABkAABZzdG9yYWdlLmdvb2dsZWFwaXMuY29tABcAAAANABgAFgQDCAQEAQUDAgMIBQgFBQEIBgYBAgEABQAFAQAAAAAzdAAAABIAAAAQADAALgJoMgVoMi0xNgVoMi0xNQVoMi0xNAhzcGR5LzMuMQZzcGR5LzMIaHR0cC8xLjEACwACAQAAMwAmACQAHQAgrulAaqUdKeVYM0F+pu6on/h6LBpOyzOKG4xFIKcoFk4ALQACAQEAKwAJCAMEAwMDAgMBAAoACgAIAB0AFwAYABkAFQChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
8
-}
8
+}

+ 3
- 3
mtglib/internal/faketls/testdata/client-hello-ok-79d01ef18a9d2621.json Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 {
2 2
   "time": 1617181365,
3 3
   "random": "8xljlOhkDlkafEF5vu3e1r3fWvh8AX548wC3hLZ3szQ=",
4
-  "session-id": "00uvDYKnFyZFKyf3HlLwWGCOyeHsPFiU5UZ+Fs5pDAU=",
4
+  "sessionId": "00uvDYKnFyZFKyf3HlLwWGCOyeHsPFiU5UZ+Fs5pDAU=",
5 5
   "host": "storage.googleapis.com",
6
-  "cipher-suite": 4867,
6
+  "cipherSuite": 4867,
7 7
   "full": "AQAB/AMD8xljlOhkDlkafEF5vu3e1r3fWvh8AX548wC3hLZ3szQg00uvDYKnFyZFKyf3HlLwWGCOyeHsPFiU5UZ+Fs5pDAUANBMDEwETAsAswCvAJMAjwArACcypwDDAL8AowCfAFMATzKgAnQCcAD0APAA1AC/ACMASAAoBAAF//wEAAQAAAAAbABkAABZzdG9yYWdlLmdvb2dsZWFwaXMuY29tABcAAAANABgAFgQDCAQEAQUDAgMIBQgFBQEIBgYBAgEABQAFAQAAAAAzdAAAABIAAAAQADAALgJoMgVoMi0xNgVoMi0xNQVoMi0xNAhzcGR5LzMuMQZzcGR5LzMIaHR0cC8xLjEACwACAQAAMwAmACQAHQAg/9P7140NtKzjyDwBf99mOy1+FjRPAPHTNQ9WxHOKpV4ALQACAQEAKwAJCAMEAwMDAgMBAAoACgAIAB0AFwAYABkAFQChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
8
-}
8
+}

+ 3
- 3
mtglib/internal/faketls/testdata/client-hello-ok-7a5569f05b118145.json Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 {
2 2
   "time": 1617181352,
3 3
   "random": "zja3MLZ8WGSfsQRtPV75+tY6gbK3zKPi1Sy7SBBafg4=",
4
-  "session-id": "qPut2yMqXa9zGLII/872SQ3d4Tfqo0uoDb7tpkRfBnA=",
4
+  "sessionId": "qPut2yMqXa9zGLII/872SQ3d4Tfqo0uoDb7tpkRfBnA=",
5 5
   "host": "storage.googleapis.com",
6
-  "cipher-suite": 4867,
6
+  "cipherSuite": 4867,
7 7
   "full": "AQAB/AMDzja3MLZ8WGSfsQRtPV75+tY6gbK3zKPi1Sy7SBBafg4gqPut2yMqXa9zGLII/872SQ3d4Tfqo0uoDb7tpkRfBnAANBMDEwETAsAswCvAJMAjwArACcypwDDAL8AowCfAFMATzKgAnQCcAD0APAA1AC/ACMASAAoBAAF//wEAAQAAAAAbABkAABZzdG9yYWdlLmdvb2dsZWFwaXMuY29tABcAAAANABgAFgQDCAQEAQUDAgMIBQgFBQEIBgYBAgEABQAFAQAAAAAzdAAAABIAAAAQADAALgJoMgVoMi0xNgVoMi0xNQVoMi0xNAhzcGR5LzMuMQZzcGR5LzMIaHR0cC8xLjEACwACAQAAMwAmACQAHQAgXviLRAqAYJ8xOLdlcsUhldI4Xl0g/s9+y2Qrd8raPEgALQACAQEAKwAJCAMEAwMDAgMBAAoACgAIAB0AFwAYABkAFQChAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
8
-}
8
+}

+ 2
- 0
mtglib/internal/obfuscated2/handshake_frame.go Zobrazit soubor

@@ -1,6 +1,8 @@
1 1
 package obfuscated2
2 2
 
3 3
 const (
4
+	// DefaultDC defines a number of the default DC to use. This value used
5
+	// only if a value from obfuscated2 handshake frame is 0 (default).
4 6
 	DefaultDC = 2
5 7
 
6 8
 	handshakeFrameLen = 64

+ 9
- 9
mtglib/proxy_opts.go Zobrazit soubor

@@ -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 uint
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
 	//

+ 1
- 1
mtglib/proxy_test.go Zobrazit soubor

@@ -166,7 +166,7 @@ func (suite *ProxyTestSuite) TestHTTPSRequest() {
166 166
 
167 167
 	jsonStruct := struct {
168 168
 		Headers struct {
169
-			TraceID string `json:"X-Amzn-Trace-Id"`
169
+			TraceID string `json:"X-Amzn-Trace-Id"` // nolint: tagliatelle
170 170
 		} `json:"headers"`
171 171
 	}{}
172 172
 

+ 5
- 2
mtglib/secret.go Zobrazit soubor

@@ -56,9 +56,12 @@ func (s Secret) MarshalText() ([]byte, error) {
56 56
 	return nil, nil
57 57
 }
58 58
 
59
-// MarshalText is to support text.Unmarshaller interface.
59
+// UnmarshalText is to support text.Unmarshaller interface.
60 60
 func (s *Secret) UnmarshalText(data []byte) error {
61
-	text := string(data)
61
+	return s.Set(string(data))
62
+}
63
+
64
+func (s *Secret) Set(text string) error {
62 65
 	if text == "" {
63 66
 		return ErrSecretEmpty
64 67
 	}

+ 8
- 2
network/init.go Zobrazit soubor

@@ -53,8 +53,14 @@ const (
53 53
 	//
54 54
 	// When circuit breaker is closed, it clears an error states each
55 55
 	// ProxyDialerResetFailuresTimeout.
56
-	ProxyDialerOpenThreshold        = 5
57
-	ProxyDialerHalfOpenTimeout      = time.Minute
56
+	ProxyDialerOpenThreshold = 5
57
+
58
+	// ProxyDialerHalfOpenTimeout defines a halfopen timeout for circuit
59
+	// breaker.
60
+	ProxyDialerHalfOpenTimeout = time.Minute
61
+
62
+	// ProxyDialerResetFailuresTimeout defines a timeout for resetting a
63
+	// failure.
58 64
 	ProxyDialerResetFailuresTimeout = 10 * time.Second
59 65
 
60 66
 	// DefaultDOHHostname defines a default IP address for DOH host.

+ 2
- 2
network/network_test.go Zobrazit soubor

@@ -42,7 +42,7 @@ func (suite *NetworkTestSuite) TestLocalHTTPRequest() {
42 42
 
43 43
 	jsonStruct := struct {
44 44
 		Headers struct {
45
-			UserAgent []string `json:"User-Agent"`
45
+			UserAgent []string `json:"User-Agent"` // nolint: tagliatelle
46 46
 		} `json:"headers"`
47 47
 	}{}
48 48
 
@@ -67,7 +67,7 @@ func (suite *NetworkTestSuite) TestRealHTTPRequest() {
67 67
 
68 68
 	jsonStruct := struct {
69 69
 		Headers struct {
70
-			UserAgent string `json:"User-Agent"`
70
+			UserAgent string `json:"User-Agent"` // nolint: tagliatelle
71 71
 		} `json:"headers"`
72 72
 	}{}
73 73
 

+ 1
- 1
network/proxy_dialer.go Zobrazit soubor

@@ -16,7 +16,7 @@ func newProxyDialer(baseDialer Dialer, proxyURL *url.URL) Dialer {
16 16
 	)
17 17
 
18 18
 	if param := params.Get("open_threshold"); param != "" {
19
-		if intNum, err := strconv.ParseUint(param, 10, 32); err == nil {
19
+		if intNum, err := strconv.ParseUint(param, 10, 32); err == nil { // nolint: gomnd
20 20
 			openThreshold = uint32(intNum)
21 21
 		}
22 22
 	}

+ 13
- 3
stats/init.go Zobrazit soubor

@@ -90,8 +90,12 @@ const (
90 90
 	MetricReplayAttacks = "replay_attacks"
91 91
 
92 92
 	// TagIPFamily defines a name of the 'ip_family' tag and all values.
93
-	TagIPFamily     = "ip_family"
93
+	TagIPFamily = "ip_family"
94
+
95
+	// TagIPFamilyIPv4 defines a value of 'ip_family' of IPv4.
94 96
 	TagIPFamilyIPv4 = "ipv4"
97
+
98
+	// TagIPFamilyIPv6 defines a value of 'ip_family' of IPv6.
95 99
 	TagIPFamilyIPv6 = "ipv6"
96 100
 
97 101
 	// TagTelegramIP defines a name of the 'telegram_ip' tag.
@@ -101,7 +105,13 @@ const (
101 105
 	TagDC = "dc"
102 106
 
103 107
 	// TagDirection defines a name of the 'direction' tag.
104
-	TagDirection           = "direction"
105
-	TagDirectionToClient   = "to_client"
108
+	TagDirection = "direction"
109
+
110
+	// TagDirectionToClient defines that traffic is sent from Telegram to a
111
+	// client.
112
+	TagDirectionToClient = "to_client"
113
+
114
+	// TagDirectionFromClient defines that traffic is sent from a client to
115
+	// Telegram.
106 116
 	TagDirectionFromClient = "from_client"
107 117
 )

+ 2
- 3
stats/prometheus.go Zobrazit soubor

@@ -119,11 +119,10 @@ func (p prometheusProcessor) EventReplayAttack(_ mtglib.EventReplayAttack) {
119 119
 }
120 120
 
121 121
 func (p prometheusProcessor) Shutdown() {
122
-	for _, v := range p.streams {
122
+	for k, v := range p.streams {
123 123
 		releaseStreamInfo(v)
124
+		delete(p.streams, k)
124 125
 	}
125
-
126
-	p.streams = make(map[string]*streamInfo)
127 126
 }
128 127
 
129 128
 // PrometheusFactory is a factory of events.Observers which collect

Načítá se…
Zrušit
Uložit