Skip to content

Commit 972dbd2

Browse files
committed
Run stringer on codes.Code
This makes error codes easier to read: fmt.Sprint(codes.OK) == "OK" instead of "0"
1 parent fd70cd3 commit 972dbd2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

codes/code_string.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// generated by stringer -type=Code; DO NOT EDIT
2+
3+
package codes
4+
5+
import "fmt"
6+
7+
const _Code_name = "OKCanceledUnknownInvalidArgumentDeadlineExceededNotFoundAlreadyExistsPermissionDeniedResourceExhaustedFailedPreconditionAbortedOutOfRangeUnimplementedInternalUnavailableDataLossUnauthenticated"
8+
9+
var _Code_index = [...]uint8{0, 2, 10, 17, 32, 48, 56, 69, 85, 102, 120, 127, 137, 150, 158, 169, 177, 192}
10+
11+
func (i Code) String() string {
12+
if i+1 >= Code(len(_Code_index)) {
13+
return fmt.Sprintf("Code(%d)", i)
14+
}
15+
return _Code_name[_Code_index[i]:_Code_index[i+1]]
16+
}

codes/codes.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ package codes // import "google.golang.org/grpc/codes"
3838
// A Code is an unsigned 32-bit error code as defined in the gRPC spec.
3939
type Code uint32
4040

41+
//go:generate stringer -type=Code
42+
4143
const (
4244
// OK is returned on success.
4345
OK Code = 0

0 commit comments

Comments
 (0)