Skip to content

Commit

Permalink
Various simplifications (gosimple)
Browse files Browse the repository at this point in the history
This fixes:
clientconn.go:948:3: should write m = cc.sc.Methods[method[:i+1]] instead of m, _ = cc.sc.Methods[method[:i+1]] (S1005)
encoding/proto/proto_test.go:43:5: should use !bytes.Equal(p.GetBody(), expectedBody) instead (S1004)
resolver/dns/dns_resolver.go:260:2: should merge variable declaration with assignment on next line (S1021)
resolver/dns/dns_resolver.go:344:2: should use 'return <expr>' instead of 'if <expr> { return <bool> }; return <bool>' (S1008)
  • Loading branch information
knweiss committed Apr 15, 2018
1 parent 2696ad3 commit 3776a03
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ func (cc *ClientConn) GetMethodConfig(method string) MethodConfig {
m, ok := cc.sc.Methods[method]
if !ok {
i := strings.LastIndex(method, "/")
m, _ = cc.sc.Methods[method[:i+1]]
m = cc.sc.Methods[method[:i+1]]
}
return m
}
Expand Down
2 changes: 1 addition & 1 deletion encoding/proto/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func marshalAndUnmarshal(t *testing.T, codec encoding.Codec, expectedBody []byte
t.Errorf("codec.Unmarshal(_) returned an error")
}

if bytes.Compare(p.GetBody(), expectedBody) != 0 {
if !bytes.Equal(p.GetBody(), expectedBody) {
t.Errorf("Unexpected body; got %v; want %v", p.GetBody(), expectedBody)
}
}
Expand Down
8 changes: 2 additions & 6 deletions resolver/dns/dns_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ func (d *dnsResolver) lookupHost() []resolver.Address {
}

func (d *dnsResolver) lookup() ([]resolver.Address, string) {
var newAddrs []resolver.Address
newAddrs = d.lookupSRV()
newAddrs := d.lookupSRV()
// Support fallback to non-balancer address.
newAddrs = append(newAddrs, d.lookupHost()...)
sc := d.lookupTXT()
Expand Down Expand Up @@ -341,10 +340,7 @@ func chosenByPercentage(a *int) bool {
}
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
if r.Intn(100)+1 > *a {
return false
}
return true
return r.Intn(100)+1 <= *a
}

func canaryingSC(js string) string {
Expand Down

0 comments on commit 3776a03

Please sign in to comment.