Chore: code style improvements (#361)

This commit is contained in:
Kirill Motkov 2019-10-14 12:13:23 +03:00 committed by Dreamacro
parent 710cd5aed2
commit f4326daaa4
4 changed files with 12 additions and 10 deletions

View file

@ -33,11 +33,12 @@ func urlToMetadata(rawURL string) (addr C.Metadata, err error) {
port := u.Port() port := u.Port()
if port == "" { if port == "" {
if u.Scheme == "https" { switch u.Scheme {
case "https":
port = "443" port = "443"
} else if u.Scheme == "http" { case "http":
port = "80" port = "80"
} else { default:
err = fmt.Errorf("%s scheme not Support", rawURL) err = fmt.Errorf("%s scheme not Support", rawURL)
return return
} }

View file

@ -28,7 +28,7 @@ func TestObservable(t *testing.T) {
} }
count := 0 count := 0
for range data { for range data {
count = count + 1 count++
} }
if count != 5 { if count != 5 {
t.Error("Revc number error") t.Error("Revc number error")
@ -46,7 +46,7 @@ func TestObservable_MutilSubscribe(t *testing.T) {
wg.Add(2) wg.Add(2)
waitCh := func(ch <-chan interface{}) { waitCh := func(ch <-chan interface{}) {
for range ch { for range ch {
count = count + 1 count++
} }
wg.Done() wg.Done()
} }

View file

@ -52,7 +52,7 @@ func (m *Mux) Read(b []byte) (int, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
m.remain = m.remain - n m.remain -= n
return n, nil return n, nil
} }

View file

@ -81,13 +81,14 @@ func (e EnhancedMode) String() string {
func putMsgToCache(c *cache.Cache, key string, msg *D.Msg) { func putMsgToCache(c *cache.Cache, key string, msg *D.Msg) {
var ttl time.Duration 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 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 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 ttl = time.Duration(msg.Extra[0].Header().Ttl) * time.Second
} else { default:
log.Debugln("[DNS] response msg error: %#v", msg) log.Debugln("[DNS] response msg error: %#v", msg)
return return
} }