From f7f76fb8b6eca46e841df95204d92926b1be0ff9 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 14 Oct 2019 12:13:23 +0300 Subject: [PATCH] Chore: code style improvements (#361) --- adapters/outbound/util.go | 7 ++++--- common/observable/observable_test.go | 4 ++-- component/v2ray-plugin/mux.go | 2 +- dns/util.go | 9 +++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/adapters/outbound/util.go b/adapters/outbound/util.go index 22b2d953..4fdbe003 100644 --- a/adapters/outbound/util.go +++ b/adapters/outbound/util.go @@ -33,11 +33,12 @@ func urlToMetadata(rawURL string) (addr C.Metadata, err error) { port := u.Port() if port == "" { - if u.Scheme == "https" { + switch u.Scheme { + case "https": port = "443" - } else if u.Scheme == "http" { + case "http": port = "80" - } else { + default: err = fmt.Errorf("%s scheme not Support", rawURL) return } diff --git a/common/observable/observable_test.go b/common/observable/observable_test.go index c3d178db..41ee272d 100644 --- a/common/observable/observable_test.go +++ b/common/observable/observable_test.go @@ -28,7 +28,7 @@ func TestObservable(t *testing.T) { } count := 0 for range data { - count = count + 1 + count++ } if count != 5 { t.Error("Revc number error") @@ -46,7 +46,7 @@ func TestObservable_MutilSubscribe(t *testing.T) { wg.Add(2) waitCh := func(ch <-chan interface{}) { for range ch { - count = count + 1 + count++ } wg.Done() } diff --git a/component/v2ray-plugin/mux.go b/component/v2ray-plugin/mux.go index 7191331b..6bff27bf 100644 --- a/component/v2ray-plugin/mux.go +++ b/component/v2ray-plugin/mux.go @@ -52,7 +52,7 @@ func (m *Mux) Read(b []byte) (int, error) { if err != nil { return 0, err } - m.remain = m.remain - n + m.remain -= n return n, nil } diff --git a/dns/util.go b/dns/util.go index e29ea1b0..cb6a1c4e 100644 --- a/dns/util.go +++ b/dns/util.go @@ -81,13 +81,14 @@ func (e EnhancedMode) String() string { func putMsgToCache(c *cache.Cache, key string, msg *D.Msg) { var ttl time.Duration - if len(msg.Answer) != 0 { + switch { + case len(msg.Answer) != 0: ttl = time.Duration(msg.Answer[0].Header().Ttl) * time.Second - } else if len(msg.Ns) != 0 { + case len(msg.Ns) != 0: ttl = time.Duration(msg.Ns[0].Header().Ttl) * time.Second - } else if len(msg.Extra) != 0 { + case len(msg.Extra) != 0: ttl = time.Duration(msg.Extra[0].Header().Ttl) * time.Second - } else { + default: log.Debugln("[DNS] response msg error: %#v", msg) return }