fix proto-gen-go-errors bug (#1047)

pull/1048/head
包子 3 years ago committed by GitHub
parent 1d0c958a04
commit c114f5c96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      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 { func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode) defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode)
code := 0 code := 0
if v, ok := defaultCode.(int32); ok { if ok := defaultCode.(int32); ok != 0 {
code = int(v) code = int(ok)
} }
if code > 600 || code < 0 { 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()))) 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 { for _, v := range enum.Values {
enumCode := code enumCode := code
eCode := proto.GetExtension(v.Desc.Options(), errors.E_Code) eCode := proto.GetExtension(v.Desc.Options(), errors.E_Code)
if v, ok := eCode.(int32); ok { if ok := eCode.(int32); ok != 0 {
enumCode = int(v) enumCode = int(ok)
} }
// If the current enumeration does not contain 'errors.code' // If the current enumeration does not contain 'errors.code'
//or the code value exceeds the range, the current enum will be skipped //or the code value exceeds the range, the current enum will be skipped

Loading…
Cancel
Save