소스 검색

Linting

tags/v2.0.0-rc1
9seconds 5 년 전
부모
커밋
9aa56191f9
6개의 변경된 파일24개의 추가작업 그리고 24개의 파일을 삭제
  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 파일 보기

@@ -87,7 +87,7 @@ func runAccessGetIP(ntw *network.Network, protocol string) net.IP {
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 91
 	if err != nil {
92 92
 		return nil
93 93
 	}

+ 2
- 2
cli_generate_secret.go 파일 보기

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

+ 9
- 9
config.go 파일 보기

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

+ 8
- 6
main.go 파일 보기

@@ -10,17 +10,18 @@ import (
10 10
 var version = "dev" // has to be set by ldflags
11 11
 
12 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 15
 		Hex      bool   `help:"Print secret in hex encoding."`
16 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 19
 		Hex        bool   `help:"Print secret in hex encoding."`
20 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 23
 	} `cmd help:"Run proxy."`
24
+	Version kong.VersionFlag `help:"Print version."`
24 25
 }
25 26
 
26 27
 func main() {
@@ -30,6 +31,7 @@ func main() {
30 31
 	ctx := kong.Parse(cli, kong.Vars{
31 32
 		"domain_front": "amazonaws.com",
32 33
 		"config_path":  "/etc/mtg.toml",
34
+		"version":      version,
33 35
 	})
34 36
 
35 37
 	switch ctx.Command() {

+ 2
- 2
mtglib/secret.go 파일 보기

@@ -15,8 +15,8 @@ type Secret struct {
15 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 20
 		return nil, nil
21 21
 	}
22 22
 

+ 2
- 4
utils.go 파일 보기

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

Loading…
취소
저장