mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-24 03:46:37 +02:00
fix proto-gen-go-errors bug (#1047)
This commit is contained in:
parent
1d0c958a04
commit
c114f5c96b
@ -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…
x
Reference in New Issue
Block a user