diff --git a/cmd/protoc-gen-go-errors/errors.go b/cmd/protoc-gen-go-errors/errors.go index eeac151ab..76222acc9 100644 --- a/cmd/protoc-gen-go-errors/errors.go +++ b/cmd/protoc-gen-go-errors/errors.go @@ -43,7 +43,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. index := 0 for _, enum := range file.Enums { skip := genErrorsReason(gen, file, g, enum) - if skip == false { + if !skip { index++ } } @@ -70,7 +70,7 @@ func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene 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 + // or the code value exceeds the range, the current enum will be skipped if enumCode > 600 || enumCode < 0 { panic(fmt.Sprintf("Enum '%s' range must be greater than 0 and less than or equal to 600", string(v.Desc.Name()))) } @@ -81,7 +81,7 @@ func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene Name: string(enum.Desc.Name()), Value: string(v.Desc.Name()), CamelValue: Case2Camel(string(v.Desc.Name())), - HttpCode: enumCode, + HTTPCode: enumCode, } ew.Errors = append(ew.Errors, err) } diff --git a/cmd/protoc-gen-go-errors/template.go b/cmd/protoc-gen-go-errors/template.go index 19c954712..1aa478810 100644 --- a/cmd/protoc-gen-go-errors/template.go +++ b/cmd/protoc-gen-go-errors/template.go @@ -10,11 +10,11 @@ var errorsTemplate = ` func Is{{.CamelValue}}(err error) bool { e := errors.FromError(err) - return e.Reason == {{.Name}}_{{.Value}}.String() && e.Code == {{.HttpCode}} + return e.Reason == {{.Name}}_{{.Value}}.String() && e.Code == {{.HTTPCode}} } func Error{{.CamelValue}}(format string, args ...interface{}) *errors.Error { - return errors.New({{.HttpCode}}, {{.Name}}_{{.Value}}.String(), fmt.Sprintf(format, args...)) + return errors.New({{.HTTPCode}}, {{.Name}}_{{.Value}}.String(), fmt.Sprintf(format, args...)) } {{- end }} @@ -23,9 +23,10 @@ func Error{{.CamelValue}}(format string, args ...interface{}) *errors.Error { type errorInfo struct { Name string Value string - HttpCode int + HTTPCode int CamelValue string } + type errorWrapper struct { Errors []*errorInfo } @@ -39,5 +40,5 @@ func (e *errorWrapper) execute() string { if err := tmpl.Execute(buf, e); err != nil { panic(err) } - return string(buf.Bytes()) + return buf.String() } diff --git a/hack/.lintcheck_failures b/hack/.lintcheck_failures index 5af78ca9c..d97c87775 100644 --- a/hack/.lintcheck_failures +++ b/hack/.lintcheck_failures @@ -1,5 +1,4 @@ ./examples -./cmd/protoc-gen-go-errors ./cmd/protoc-gen-go-http ./cmd/kratos ./contrib/metrics/datadog