Skip to content

Commit

Permalink
Feedback: use byte for timeout lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Sep 26, 2023
1 parent 1b6eed7 commit 1b36244
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions protocol_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func grpcParseTimeout(timeout string) (time.Duration, error) {
if timeout == "" {
return 0, errNoTimeout
}
unit := grpcTimeoutUnitLookup(timeout[len(timeout)-1:])
unit := grpcTimeoutUnitLookup(timeout[len(timeout)-1])
if unit == 0 {
return 0, fmt.Errorf("protocol error: timeout %q has invalid unit", timeout)
}
Expand Down Expand Up @@ -795,19 +795,19 @@ func grpcEncodeTimeout(timeout time.Duration) string {
return strconv.FormatInt(div(timeout, time.Hour), 10) + "H"
}

func grpcTimeoutUnitLookup(unit string) time.Duration {
func grpcTimeoutUnitLookup(unit byte) time.Duration {
switch unit {
case "n":
case 'n':
return time.Nanosecond
case "u":
case 'u':
return time.Microsecond
case "m":
case 'm':
return time.Millisecond
case "S":
case 'S':
return time.Second
case "M":
case 'M':
return time.Minute
case "H":
case 'H':
return time.Hour
default:
return 0
Expand Down

1 comment on commit 1b36244

@mattrobenolt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.