diff --git a/cmd/protoc-gen-go-errors/errors.go b/cmd/protoc-gen-go-errors/errors.go index db5e51952..a827c0719 100644 --- a/cmd/protoc-gen-go-errors/errors.go +++ b/cmd/protoc-gen-go-errors/errors.go @@ -4,6 +4,9 @@ import ( "fmt" "strings" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2/errors" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/proto" @@ -14,6 +17,8 @@ const ( fmtPackage = protogen.GoImportPath("fmt") ) +var enCases = cases.Title(language.AmericanEnglish) + // generateFile generates a _errors.pb.go file containing kratos errors definitions. func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile { if len(file.Enums) == 0 { @@ -98,10 +103,10 @@ func case2Camel(name string) string { if upperName == name { name = strings.ToLower(name) } - return strings.Title(name) + return enCases.String(name) } name = strings.ToLower(name) name = strings.Replace(name, "_", " ", -1) - name = strings.Title(name) + name = enCases.String(name) return strings.Replace(name, " ", "", -1) } diff --git a/cmd/protoc-gen-go-errors/go.mod b/cmd/protoc-gen-go-errors/go.mod index 423d91c8e..4661ee6a4 100644 --- a/cmd/protoc-gen-go-errors/go.mod +++ b/cmd/protoc-gen-go-errors/go.mod @@ -2,4 +2,7 @@ module github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2 go 1.16 -require google.golang.org/protobuf v1.27.1 +require ( + golang.org/x/text v0.3.7 // indirect + google.golang.org/protobuf v1.27.1 +) diff --git a/cmd/protoc-gen-go-errors/go.sum b/cmd/protoc-gen-go-errors/go.sum index 03b1917b5..5146f899e 100644 --- a/cmd/protoc-gen-go-errors/go.sum +++ b/cmd/protoc-gen-go-errors/go.sum @@ -1,6 +1,9 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=