зеркало из https://github.com/arthurnn/twirp-ruby.git
Only append "Service" suffix when services are not properly named.
Protobuf services should end in `Service`. This is a [buf lint rule](https://github.com/bufbuild/buf-examples/blob/main/linting/bad/acme/weather/v1/weather.proto#L39), recommended via [the protobuf style guide](https://developers.google.com/protocol-buffers/docs/style#services), and demonstrated in [Twirp Best Practices](https://twitchtv.github.io/twirp/docs/best_practices.html)) Therefore, we only append "Service" to fixup services that are not well named. This avoids generating e.g. "MessagesServiceService".
This commit is contained in:
Родитель
cd830052b4
Коммит
8d7ad0adf4
|
@ -109,7 +109,12 @@ func (g *generator) generateRubyCode(file *descriptor.FileDescriptorProto, pbFil
|
|||
for i, service := range file.Service {
|
||||
svcName := service.GetName()
|
||||
|
||||
print(b, "%sclass %sService < ::Twirp::Service", indent, camelCase(svcName))
|
||||
// Well-named services already end in "Service"; fixup services that don't.
|
||||
if !strings.HasSuffix(svcName, "Service") {
|
||||
svcName += "Service"
|
||||
}
|
||||
|
||||
print(b, "%sclass %s < ::Twirp::Service", indent, camelCase(svcName))
|
||||
if pkgName != "" {
|
||||
print(b, "%s package '%s'", indent, pkgName)
|
||||
}
|
||||
|
@ -125,7 +130,7 @@ func (g *generator) generateRubyCode(file *descriptor.FileDescriptorProto, pbFil
|
|||
print(b, "")
|
||||
|
||||
print(b, "%sclass %sClient < ::Twirp::Client", indent, camelCase(svcName))
|
||||
print(b, "%s client_for %sService", indent, camelCase(svcName))
|
||||
print(b, "%s client_for %s", indent, camelCase(svcName))
|
||||
print(b, "%send", indent)
|
||||
if i < len(file.Service)-1 {
|
||||
print(b, "")
|
||||
|
|
Загрузка…
Ссылка в новой задаче