Skip to content

Commit

Permalink
fix(cmd/protoc-gen-go-errors):fix lint problem (#1919)
Browse files Browse the repository at this point in the history
use cases.Title instead of strings.Title
  • Loading branch information
Casper-Mars committed Apr 8, 2022
1 parent d5a2fb5 commit 4f21094
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions cmd/protoc-gen-go-errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)

This comment has been minimized.

Copy link
@fifsky

fifsky Apr 8, 2022

Contributor

This causes the unit tests to fail

return strings.Replace(name, " ", "", -1)
}
5 changes: 4 additions & 1 deletion cmd/protoc-gen-go-errors/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
3 changes: 3 additions & 0 deletions cmd/protoc-gen-go-errors/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 4f21094

Please sign in to comment.