From c114f5c96bb2e1fc95cd6d11b9b9d5b6a43801ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=AD=90?= Date: Sun, 13 Jun 2021 15:01:23 +0800 Subject: [PATCH] fix proto-gen-go-errors bug (#1047) --- cmd/protoc-gen-go-errors/errors.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/protoc-gen-go-errors/errors.go b/cmd/protoc-gen-go-errors/errors.go index 314395dcd..c4338097d 100644 --- a/cmd/protoc-gen-go-errors/errors.go +++ b/cmd/protoc-gen-go-errors/errors.go @@ -56,8 +56,8 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool { defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode) code := 0 - if v, ok := defaultCode.(int32); ok { - code = int(v) + if ok := defaultCode.(int32); ok != 0 { + code = int(ok) } if code > 600 || code < 0 { panic(fmt.Sprintf("Enum '%s' range must be greater than 0 and less than or equal to 600", string(enum.Desc.Name()))) @@ -66,8 +66,8 @@ func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene for _, v := range enum.Values { enumCode := code eCode := proto.GetExtension(v.Desc.Options(), errors.E_Code) - if v, ok := eCode.(int32); ok { - enumCode = int(v) + if ok := eCode.(int32); ok != 0 { + enumCode = int(ok) } // If the current enumeration does not contain 'errors.code' //or the code value exceeds the range, the current enum will be skipped