Browse Source

apply coding style

Shelikhoo 4 years ago
parent
commit
d7c9a98d76

+ 6 - 6
app/dispatcher/fakednssniffer.go

@@ -74,10 +74,7 @@ type DNSThenOthersSniffResult struct {
 }
 }
 
 
 func (f DNSThenOthersSniffResult) IsProtoSubsetOf(protocolName string) bool {
 func (f DNSThenOthersSniffResult) IsProtoSubsetOf(protocolName string) bool {
-	if strings.HasPrefix(protocolName, f.protocolOriginalName) {
-		return true
-	}
-	return false
+	return strings.HasPrefix(protocolName, f.protocolOriginalName)
 }
 }
 
 
 func (DNSThenOthersSniffResult) Protocol() string {
 func (DNSThenOthersSniffResult) Protocol() string {
@@ -88,7 +85,10 @@ func (f DNSThenOthersSniffResult) Domain() string {
 	return f.domainName
 	return f.domainName
 }
 }
 
 
-func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) (protocolSnifferWithMetadata, error) {
+func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) (
+	protocolSnifferWithMetadata, error) { // nolint: unparam
+	// ctx may be used in the future
+	_ = ctx
 	return protocolSnifferWithMetadata{
 	return protocolSnifferWithMetadata{
 		protocolSniffer: func(ctx context.Context, bytes []byte) (SniffResult, error) {
 		protocolSniffer: func(ctx context.Context, bytes []byte) (SniffResult, error) {
 			ipAddressInRangeValue := &ipAddressInRangeOpt{}
 			ipAddressInRangeValue := &ipAddressInRangeOpt{}
@@ -98,7 +98,7 @@ func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWit
 				return result, nil
 				return result, nil
 			}
 			}
 			if ipAddressInRangeValue.addressInRange != nil {
 			if ipAddressInRangeValue.addressInRange != nil {
-				if *ipAddressInRangeValue.addressInRange == true {
+				if *ipAddressInRangeValue.addressInRange {
 					for _, v := range others {
 					for _, v := range others {
 						if v.metadataSniffer || bytes != nil {
 						if v.metadataSniffer || bytes != nil {
 							if result, err := v.protocolSniffer(ctx, bytes); err == nil {
 							if result, err := v.protocolSniffer(ctx, bytes); err == nil {

+ 1 - 0
app/dns/fakedns/fakedns_test.go

@@ -127,6 +127,7 @@ func TestFakeDNSMulti(t *testing.T) {
 		}},
 		}},
 	},
 	},
 	)
 	)
+	common.Must(err)
 
 
 	err = fakeMulti.Start()
 	err = fakeMulti.Start()
 
 

+ 5 - 5
app/observatory/observer.go

@@ -73,14 +73,14 @@ func (o *Observer) background() {
 			}
 			}
 			time.Sleep(time.Second * 10)
 			time.Sleep(time.Second * 10)
 		}
 		}
-
 	}
 	}
 }
 }
 
 
 func (o *Observer) updateStatus(outbounds []string) {
 func (o *Observer) updateStatus(outbounds []string) {
 	o.statusLock.Lock()
 	o.statusLock.Lock()
 	defer o.statusLock.Unlock()
 	defer o.statusLock.Unlock()
-	//TODO should remove old inbound that is removed
+	// TODO should remove old inbound that is removed
+	_ = outbounds
 }
 }
 
 
 func (o *Observer) probe(outbound string) ProbeResult {
 func (o *Observer) probe(outbound string) ProbeResult {
@@ -93,7 +93,7 @@ func (o *Observer) probe(outbound string) ProbeResult {
 		DialContext: func(ctx context.Context, network string, addr string) (net.Conn, error) {
 		DialContext: func(ctx context.Context, network string, addr string) (net.Conn, error) {
 			var connection net.Conn
 			var connection net.Conn
 			taskErr := task.Run(ctx, func() error {
 			taskErr := task.Run(ctx, func() error {
-				//MUST use V2Fly's built in context system
+				// MUST use V2Fly's built in context system
 				dest, err := v2net.ParseDestination(network + ":" + addr)
 				dest, err := v2net.ParseDestination(network + ":" + addr)
 				if err != nil {
 				if err != nil {
 					return newError("cannot understand address").Base(err)
 					return newError("cannot understand address").Base(err)
@@ -111,7 +111,7 @@ func (o *Observer) probe(outbound string) ProbeResult {
 			}
 			}
 			return connection, nil
 			return connection, nil
 		},
 		},
-		TLSHandshakeTimeout: time.Duration(time.Second * 5),
+		TLSHandshakeTimeout: time.Second * 5,
 	}
 	}
 	httpClient := &http.Client{
 	httpClient := &http.Client{
 		Transport: &httpTransport,
 		Transport: &httpTransport,
@@ -119,7 +119,7 @@ func (o *Observer) probe(outbound string) ProbeResult {
 			return http.ErrUseLastResponse
 			return http.ErrUseLastResponse
 		},
 		},
 		Jar:     nil,
 		Jar:     nil,
-		Timeout: time.Duration(time.Second * 5),
+		Timeout: time.Second * 5,
 	}
 	}
 	var GETTime time.Duration
 	var GETTime time.Duration
 	err := task.Run(o.ctx, func() error {
 	err := task.Run(o.ctx, func() error {

+ 0 - 1
app/router/config.go

@@ -175,6 +175,5 @@ func (br *BalancingRule) Build(ohm outbound.Manager) (*Balancer, error) {
 			strategy:  &RandomStrategy{},
 			strategy:  &RandomStrategy{},
 			ohm:       ohm,
 			ohm:       ohm,
 		}, nil
 		}, nil
-
 	}
 	}
 }
 }

+ 1 - 0
app/router/router.go

@@ -6,6 +6,7 @@ package router
 
 
 import (
 import (
 	"context"
 	"context"
+
 	core "github.com/v2fly/v2ray-core/v4"
 	core "github.com/v2fly/v2ray-core/v4"
 	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/features/dns"
 	"github.com/v2fly/v2ray-core/v4/features/dns"

+ 1 - 1
app/router/strategy_leastping.go

@@ -47,7 +47,7 @@ func (l *LeastPingStrategy) PickOutbound(strings []string) string {
 		return selectedOutboundName
 		return selectedOutboundName
 	}
 	}
 
 
-	//No way to understand observeReport
+	// No way to understand observeReport
 	return ""
 	return ""
 }
 }
 
 

+ 1 - 1
infra/conf/v2ray.go

@@ -580,7 +580,7 @@ func (c *Config) Build() (*core.Config, error) {
 		config.App = append(config.App, serial.ToTypedMessage(r))
 		config.App = append(config.App, serial.ToTypedMessage(r))
 	}
 	}
 
 
-	//Load Additional Services that do not have a json translator
+	// Load Additional Services that do not have a json translator
 
 
 	if msg, err := c.BuildServices(c.Services); err != nil {
 	if msg, err := c.BuildServices(c.Services); err != nil {
 		developererr := newError("Loading a V2Ray Features as a service is intended for developers only. " +
 		developererr := newError("Loading a V2Ray Features as a service is intended for developers only. " +