fix(cmd/protoc-gen-go-errors):fix lint problem (#1919)

use cases.Title instead of strings.Title
pull/1923/head
Casper-Mars 3 years ago committed by GitHub
parent d5a2fb59ad
commit 4f21094a56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      cmd/protoc-gen-go-errors/errors.go
  2. 5
      cmd/protoc-gen-go-errors/go.mod
  3. 3
      cmd/protoc-gen-go-errors/go.sum

@ -4,6 +4,9 @@ import (
"fmt" "fmt"
"strings" "strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2/errors" "github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2/errors"
"google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -14,6 +17,8 @@ const (
fmtPackage = protogen.GoImportPath("fmt") fmtPackage = protogen.GoImportPath("fmt")
) )
var enCases = cases.Title(language.AmericanEnglish)
// generateFile generates a _errors.pb.go file containing kratos errors definitions. // generateFile generates a _errors.pb.go file containing kratos errors definitions.
func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile { func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile {
if len(file.Enums) == 0 { if len(file.Enums) == 0 {
@ -98,10 +103,10 @@ func case2Camel(name string) string {
if upperName == name { if upperName == name {
name = strings.ToLower(name) name = strings.ToLower(name)
} }
return strings.Title(name) return enCases.String(name)
} }
name = strings.ToLower(name) name = strings.ToLower(name)
name = strings.Replace(name, "_", " ", -1) name = strings.Replace(name, "_", " ", -1)
name = strings.Title(name) name = enCases.String(name)
return strings.Replace(name, " ", "", -1) return strings.Replace(name, " ", "", -1)
} }

@ -2,4 +2,7 @@ module github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2
go 1.16 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
)

@ -1,6 +1,9 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 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 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 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 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=

Loading…
Cancel
Save