Skip to content

Commit 7715b32

Browse files
Use map to lookup status code
Co-authored-by: Aubrey Dean <[email protected]>
1 parent 456ebca commit 7715b32

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

grpc/options.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,11 @@ func ReportAlways(err error) bool {
5050

5151
// ReportOnCodes returns true if error code matches on of the given codes.
5252
func ReportOnCodes(cc ...codes.Code) ReportOn {
53+
cm := make(map[codes.Code]bool)
54+
for _, c := range cc {
55+
cm[c] = true
56+
}
5357
return func(err error) bool {
54-
c := status.Code(err)
55-
for i := range cc {
56-
if c == cc[i] {
57-
return true
58-
}
59-
}
60-
61-
return false
58+
return cm[status.Code(err)]
6259
}
6360
}

0 commit comments

Comments
 (0)