Skip to content

Commit

Permalink
Use map to lookup status code
Browse files Browse the repository at this point in the history
Co-authored-by: Aubrey Dean <[email protected]>
  • Loading branch information
shouichi and spaceweasel committed Jan 21, 2021
1 parent 456ebca commit 93183e7
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions grpc/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ func ReportAlways(err error) bool {

// ReportOnCodes returns true if error code matches on of the given codes.
func ReportOnCodes(cc ...codes.Code) ReportOn {
cm := make(map[codes.Code]bool)
for _, c := range cc {
cm[c] = true
}
return func(err error) bool {
c := status.Code(err)
for i := range cc {
if c == cc[i] {
return true
}
}

return false
return cm[status.Code(err)]
}
}

0 comments on commit 93183e7

Please sign in to comment.