Przeglądaj źródła

Linting

tags/v2.0.0-rc1
9seconds 5 lat temu
rodzic
commit
9aa56191f9
6 zmienionych plików z 24 dodań i 24 usunięć
  1. 1
    1
      cli_access.go
  2. 2
    2
      cli_generate_secret.go
  3. 9
    9
      config.go
  4. 8
    6
      main.go
  5. 2
    2
      mtglib/secret.go
  6. 2
    4
      utils.go

+ 1
- 1
cli_access.go Wyświetl plik

87
 		},
87
 		},
88
 	}
88
 	}
89
 
89
 
90
-	resp, err := client.Get("https://ifconfig.co")
90
+	resp, err := client.Get("https://ifconfig.co") // nolint: bodyclose, noctx
91
 	if err != nil {
91
 	if err != nil {
92
 		return nil
92
 		return nil
93
 	}
93
 	}

+ 2
- 2
cli_generate_secret.go Wyświetl plik

10
 	secret := mtglib.GenerateSecret(cli.GenerateSecret.HostName)
10
 	secret := mtglib.GenerateSecret(cli.GenerateSecret.HostName)
11
 
11
 
12
 	if cli.GenerateSecret.Hex {
12
 	if cli.GenerateSecret.Hex {
13
-		fmt.Println(secret.Hex())
13
+		fmt.Println(secret.Hex()) // nolint: forbidigo
14
 	} else {
14
 	} else {
15
-		fmt.Println(secret.Base64())
15
+		fmt.Println(secret.Base64()) // nolint: forbidigo
16
 	}
16
 	}
17
 }
17
 }

+ 9
- 9
config.go Wyświetl plik

43
 	return nil
43
 	return nil
44
 }
44
 }
45
 
45
 
46
-func (c configTypeHostPort) MarshalText() ([]byte, error) {
46
+func (c configTypeHostPort) MarshalText() ([]byte, error) { // nolint: unparam
47
 	return []byte(c.String()), nil
47
 	return []byte(c.String()), nil
48
 }
48
 }
49
 
49
 
118
 	return nil
118
 	return nil
119
 }
119
 }
120
 
120
 
121
-func (c configTypeBytes) MarshalText() ([]byte, error) {
121
+func (c configTypeBytes) MarshalText() ([]byte, error) { // nolint: unparam
122
 	return []byte(c.String()), nil
122
 	return []byte(c.String()), nil
123
 }
123
 }
124
 
124
 
155
 	return nil
155
 	return nil
156
 }
156
 }
157
 
157
 
158
-func (c configTypePreferIP) MarshalText() ([]byte, error) {
158
+func (c configTypePreferIP) MarshalText() ([]byte, error) { // nolint: unparam
159
 	return []byte(c.value), nil
159
 	return []byte(c.value), nil
160
 }
160
 }
161
 
161
 
194
 	return nil
194
 	return nil
195
 }
195
 }
196
 
196
 
197
-func (c configTypeDuration) MarshalText() ([]byte, error) {
197
+func (c configTypeDuration) MarshalText() ([]byte, error) { // nolint: unparam
198
 	return []byte(c.value.String()), nil
198
 	return []byte(c.value.String()), nil
199
 }
199
 }
200
 
200
 
229
 	return nil
229
 	return nil
230
 }
230
 }
231
 
231
 
232
-func (c *configTypeFloat) MarshalText() ([]byte, error) {
232
+func (c *configTypeFloat) MarshalText() ([]byte, error) { // nolint: unparam
233
 	return []byte(c.String()), nil
233
 	return []byte(c.String()), nil
234
 }
234
 }
235
 
235
 
264
 	return nil
264
 	return nil
265
 }
265
 }
266
 
266
 
267
-func (c *configTypeIP) MarshalText() ([]byte, error) {
267
+func (c *configTypeIP) MarshalText() ([]byte, error) { // nolint: unparam
268
 	return []byte(c.String()), nil
268
 	return []byte(c.String()), nil
269
 }
269
 }
270
 
270
 
303
 	return nil
303
 	return nil
304
 }
304
 }
305
 
305
 
306
-func (c *configTypeURL) MarshalText() ([]byte, error) {
306
+func (c *configTypeURL) MarshalText() ([]byte, error) { // nolint: unparam
307
 	return []byte(c.String()), nil
307
 	return []byte(c.String()), nil
308
 }
308
 }
309
 
309
 
343
 	return nil
343
 	return nil
344
 }
344
 }
345
 
345
 
346
-func (c configTypeMetricPrefix) MarshalText() ([]byte, error) {
346
+func (c configTypeMetricPrefix) MarshalText() ([]byte, error) { // nolint: unparam
347
 	return []byte(c.String()), nil
347
 	return []byte(c.String()), nil
348
 }
348
 }
349
 
349
 
371
 	return nil
371
 	return nil
372
 }
372
 }
373
 
373
 
374
-func (c configTypeHTTPPath) MarshalText() ([]byte, error) {
374
+func (c configTypeHTTPPath) MarshalText() ([]byte, error) { // nolint: unparam
375
 	return []byte(c.String()), nil
375
 	return []byte(c.String()), nil
376
 }
376
 }
377
 
377
 

+ 8
- 6
main.go Wyświetl plik

10
 var version = "dev" // has to be set by ldflags
10
 var version = "dev" // has to be set by ldflags
11
 
11
 
12
 type CLI struct {
12
 type CLI struct {
13
-	GenerateSecret struct {
14
-		HostName string `arg optional help:"Hostname to use for domain fronting. Default is '${domain_front}'." name:"hostname" default:"${domain_front}"`
13
+	GenerateSecret struct { // nolint: govet
14
+		HostName string `arg optional help:"Hostname to use for domain fronting. Default is '${domain_front}'." name:"hostname" default:"${domain_front}"` // nolint: lll, govet
15
 		Hex      bool   `help:"Print secret in hex encoding."`
15
 		Hex      bool   `help:"Print secret in hex encoding."`
16
 	} `cmd help:"Generate new proxy secret."`
16
 	} `cmd help:"Generate new proxy secret."`
17
-	Access struct {
18
-		ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"`
17
+	Access struct { // nolint: govet
18
+		ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"` // nolint: lll, govet
19
 		Hex        bool   `help:"Print secret in hex encoding."`
19
 		Hex        bool   `help:"Print secret in hex encoding."`
20
 	} `cmd help:"Print access information."`
20
 	} `cmd help:"Print access information."`
21
-	Run struct {
22
-		ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"`
21
+	Run struct { // nolint: govet
22
+		ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"` // nolint: lll, govet
23
 	} `cmd help:"Run proxy."`
23
 	} `cmd help:"Run proxy."`
24
+	Version kong.VersionFlag `help:"Print version."`
24
 }
25
 }
25
 
26
 
26
 func main() {
27
 func main() {
30
 	ctx := kong.Parse(cli, kong.Vars{
31
 	ctx := kong.Parse(cli, kong.Vars{
31
 		"domain_front": "amazonaws.com",
32
 		"domain_front": "amazonaws.com",
32
 		"config_path":  "/etc/mtg.toml",
33
 		"config_path":  "/etc/mtg.toml",
34
+		"version":      version,
33
 	})
35
 	})
34
 
36
 
35
 	switch ctx.Command() {
37
 	switch ctx.Command() {

+ 2
- 2
mtglib/secret.go Wyświetl plik

15
 	Host string
15
 	Host string
16
 }
16
 }
17
 
17
 
18
-func (s *Secret) MarshalText() ([]byte, error) {
19
-	if s == nil {
18
+func (s Secret) MarshalText() ([]byte, error) {
19
+	if s.Key == nil {
20
 		return nil, nil
20
 		return nil, nil
21
 	}
21
 	}
22
 
22
 

+ 2
- 4
utils.go Wyświetl plik

28
 		return nil, fmt.Errorf("cannot build a default dialer: %w", err)
28
 		return nil, fmt.Errorf("cannot build a default dialer: %w", err)
29
 	}
29
 	}
30
 
30
 
31
-	proxyURLs := make([]*url.URL, len(conf.Network.Proxies))
31
+	proxyURLs := make([]*url.URL, 0, len(conf.Network.Proxies))
32
 
32
 
33
 	for _, v := range conf.Network.Proxies {
33
 	for _, v := range conf.Network.Proxies {
34
 		if value := v.Value(nil); value != nil {
34
 		if value := v.Value(nil); value != nil {
41
 		return network.NewNetwork(baseDialer, dohIP, httpTimeout)
41
 		return network.NewNetwork(baseDialer, dohIP, httpTimeout)
42
 	case 1:
42
 	case 1:
43
 		socksDialer, err := network.NewSocks5Dialer(baseDialer, proxyURLs[0])
43
 		socksDialer, err := network.NewSocks5Dialer(baseDialer, proxyURLs[0])
44
-
45
 		if err != nil {
44
 		if err != nil {
46
 			return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
45
 			return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
47
 		}
46
 		}
51
 
50
 
52
 	socksDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, proxyURLs)
51
 	socksDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, proxyURLs)
53
 	if err != nil {
52
 	if err != nil {
54
-
55
 		return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
53
 		return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
56
 	}
54
 	}
57
 
55
 
59
 }
57
 }
60
 
58
 
61
 func exhaustResponse(response *http.Response) {
59
 func exhaustResponse(response *http.Response) {
62
-	io.Copy(ioutil.Discard, response.Body)
60
+	io.Copy(ioutil.Discard, response.Body) // nolint: errcheck
63
 	response.Body.Close()
61
 	response.Body.Close()
64
 }
62
 }

Ładowanie…
Anuluj
Zapisz