From f855d878c281285bd8f468af0dba2521e4f211db Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 8 Sep 2021 20:55:25 +0300 Subject: Update protoc plugin, Update serverOptions, Update codec. Signed-off-by: Valery Piashchynski --- go.mod | 1 + go.sum | 1 + plugins/grpc/codec.go | 5 + plugins/grpc/config.go | 8 ++ plugins/grpc/plugin.go | 8 ++ plugins/grpc/protoc-gen-php-grpc/main.go | 68 ---------- plugins/grpc/protoc-gen-php-grpc/php/generate.go | 57 --------- plugins/grpc/protoc-gen-php-grpc/php/keywords.go | 139 --------------------- plugins/grpc/protoc-gen-php-grpc/php/ns.go | 103 --------------- plugins/grpc/protoc-gen-php-grpc/php/template.go | 103 --------------- .../protoc_plugins/protoc-gen-php-grpc/main.go | 68 ++++++++++ .../protoc-gen-php-grpc/php/generate.go | 57 +++++++++ .../protoc-gen-php-grpc/php/keywords.go | 139 +++++++++++++++++++++ .../protoc_plugins/protoc-gen-php-grpc/php/ns.go | 103 +++++++++++++++ .../protoc-gen-php-grpc/php/template.go | 103 +++++++++++++++ plugins/grpc/server.go | 119 ++++++++++++++++++ tests/plugins/grpc/configs/.rr-grpc-init.yaml | 50 ++++++++ tests/plugins/grpc/plugin_test.go | 2 +- tests/plugins/logger/logger_test.go | 24 ++-- 19 files changed, 675 insertions(+), 483 deletions(-) delete mode 100644 plugins/grpc/protoc-gen-php-grpc/main.go delete mode 100644 plugins/grpc/protoc-gen-php-grpc/php/generate.go delete mode 100644 plugins/grpc/protoc-gen-php-grpc/php/keywords.go delete mode 100644 plugins/grpc/protoc-gen-php-grpc/php/ns.go delete mode 100644 plugins/grpc/protoc-gen-php-grpc/php/template.go create mode 100644 plugins/grpc/protoc_plugins/protoc-gen-php-grpc/main.go create mode 100644 plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/generate.go create mode 100644 plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/keywords.go create mode 100644 plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/ns.go create mode 100644 plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/template.go create mode 100644 plugins/grpc/server.go diff --git a/go.mod b/go.mod index 97e2bdc6..b7141c4a 100644 --- a/go.mod +++ b/go.mod @@ -88,6 +88,7 @@ require ( go.uber.org/atomic v1.9.0 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.5 // indirect + google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect gopkg.in/ini.v1 v1.63.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect diff --git a/go.sum b/go.sum index 6096347d..7dec39f0 100644 --- a/go.sum +++ b/go.sum @@ -769,6 +769,7 @@ google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c h1:wtujag7C+4D6KMoulW9YauvK2lgdvCMS260jsqqBXr0= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= diff --git a/plugins/grpc/codec.go b/plugins/grpc/codec.go index dd299601..aeb373b9 100644 --- a/plugins/grpc/codec.go +++ b/plugins/grpc/codec.go @@ -4,6 +4,7 @@ import "google.golang.org/grpc/encoding" type rawMessage []byte +const cName string = "proto" const rm string = "rawMessage" func (r rawMessage) Reset() {} @@ -31,6 +32,10 @@ func (c *codec) Unmarshal(data []byte, v interface{}) error { return c.base.Unmarshal(data, v) } +func (c *codec) Name() string { + return cName +} + // String return codec name. func (c *codec) String() string { return "raw:" + c.base.Name() diff --git a/plugins/grpc/config.go b/plugins/grpc/config.go index 9a9f8c2c..53c50e22 100644 --- a/plugins/grpc/config.go +++ b/plugins/grpc/config.go @@ -32,3 +32,11 @@ type TLS struct { func (c *Config) InitDefaults() { } + +func (c *Config) EnableTLS() bool { + if c.TLS != nil { + return (c.TLS.RootCA != "" && c.TLS.Key != "" && c.TLS.Cert != "") || (c.TLS.Key != "" && c.TLS.Cert != "") + } + + return false +} diff --git a/plugins/grpc/plugin.go b/plugins/grpc/plugin.go index 4871a8a7..b424c5d0 100644 --- a/plugins/grpc/plugin.go +++ b/plugins/grpc/plugin.go @@ -4,6 +4,8 @@ import ( "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/logger" + "google.golang.org/grpc" + "google.golang.org/grpc/encoding" ) const ( @@ -11,6 +13,9 @@ const ( ) type Plugin struct { + config *Config + opts []grpc.ServerOption + cfg config.Configurer log logger.Logger } @@ -18,6 +23,9 @@ type Plugin struct { func (p *Plugin) Init(cfg config.Configurer, log logger.Logger) error { const op = errors.Op("grpc_plugin_init") + // register the codec + encoding.RegisterCodec(&codec{}) + return nil } diff --git a/plugins/grpc/protoc-gen-php-grpc/main.go b/plugins/grpc/protoc-gen-php-grpc/main.go deleted file mode 100644 index c9c4a573..00000000 --- a/plugins/grpc/protoc-gen-php-grpc/main.go +++ /dev/null @@ -1,68 +0,0 @@ -// MIT License -// -// Copyright (c) 2018 SpiralScout -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package main - -import ( - "io" - "io/ioutil" - "os" - - "github.com/spiral/roadrunner/v2/plugins/grpc/protoc-gen-php-grpc/php" - "google.golang.org/protobuf/proto" - plugin "google.golang.org/protobuf/types/pluginpb" -) - -func main() { - req, err := readRequest(os.Stdin) - if err != nil { - panic(err) - } - - if err = writeResponse(os.Stdout, php.Generate(req)); err != nil { - panic(err) - } -} - -func readRequest(in io.Reader) (*plugin.CodeGeneratorRequest, error) { - data, err := ioutil.ReadAll(in) - if err != nil { - return nil, err - } - - req := new(plugin.CodeGeneratorRequest) - if err = proto.Unmarshal(data, req); err != nil { - return nil, err - } - - return req, nil -} - -func writeResponse(out io.Writer, resp *plugin.CodeGeneratorResponse) error { - data, err := proto.Marshal(resp) - if err != nil { - return err - } - - _, err = out.Write(data) - return err -} diff --git a/plugins/grpc/protoc-gen-php-grpc/php/generate.go b/plugins/grpc/protoc-gen-php-grpc/php/generate.go deleted file mode 100644 index 03c48ac8..00000000 --- a/plugins/grpc/protoc-gen-php-grpc/php/generate.go +++ /dev/null @@ -1,57 +0,0 @@ -// MIT License -// -// Copyright (c) 2018 SpiralScout -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package php - -import ( - desc "google.golang.org/protobuf/types/descriptorpb" - plugin "google.golang.org/protobuf/types/pluginpb" -) - -// Generate generates needed service classes -func Generate(req *plugin.CodeGeneratorRequest) *plugin.CodeGeneratorResponse { - resp := &plugin.CodeGeneratorResponse{} - - for _, file := range req.ProtoFile { - for _, service := range file.Service { - resp.File = append(resp.File, generate(req, file, service)) - } - } - - return resp -} - -func generate( - req *plugin.CodeGeneratorRequest, - file *desc.FileDescriptorProto, - service *desc.ServiceDescriptorProto, -) *plugin.CodeGeneratorResponse_File { - return &plugin.CodeGeneratorResponse_File{ - Name: str(filename(file, service.Name)), - Content: str(body(req, file, service)), - } -} - -// helper to convert string into string pointer -func str(str string) *string { - return &str -} diff --git a/plugins/grpc/protoc-gen-php-grpc/php/keywords.go b/plugins/grpc/protoc-gen-php-grpc/php/keywords.go deleted file mode 100644 index 32579e33..00000000 --- a/plugins/grpc/protoc-gen-php-grpc/php/keywords.go +++ /dev/null @@ -1,139 +0,0 @@ -// MIT License -// -// Copyright (c) 2018 SpiralScout -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package php - -import ( - "bytes" - "strings" - "unicode" -) - -// @see https://github.com/protocolbuffers/protobuf/blob/master/php/ext/google/protobuf/protobuf.c#L168 -var reservedKeywords = []string{ - "abstract", "and", "array", "as", "break", - "callable", "case", "catch", "class", "clone", - "const", "continue", "declare", "default", "die", - "do", "echo", "else", "elseif", "empty", - "enddeclare", "endfor", "endforeach", "endif", "endswitch", - "endwhile", "eval", "exit", "extends", "final", - "for", "foreach", "function", "global", "goto", - "if", "implements", "include", "include_once", "instanceof", - "insteadof", "interface", "isset", "list", "namespace", - "new", "or", "print", "private", "protected", - "public", "require", "require_once", "return", "static", - "switch", "throw", "trait", "try", "unset", - "use", "var", "while", "xor", "int", - "float", "bool", "string", "true", "false", - "null", "void", "iterable", -} - -// Check if given name/keyword is reserved by php. -func isReserved(name string) bool { - name = strings.ToLower(name) - for _, k := range reservedKeywords { - if name == k { - return true - } - } - - return false -} - -// generate php namespace or path -func namespace(pkg *string, sep string) string { - if pkg == nil { - return "" - } - - result := bytes.NewBuffer(nil) - for _, p := range strings.Split(*pkg, ".") { - result.WriteString(identifier(p, "")) - result.WriteString(sep) - } - - return strings.Trim(result.String(), sep) -} - -// create php identifier for class or message -func identifier(name string, suffix string) string { - name = Camelize(name) - if suffix != "" { - return name + Camelize(suffix) - } - - return name -} - -func resolveReserved(identifier string, pkg string) string { - if isReserved(strings.ToLower(identifier)) { - if pkg == ".google.protobuf" { - return "GPB" + identifier - } - return "PB" + identifier - } - - return identifier -} - -// Camelize "dino_party" -> "DinoParty" -func Camelize(word string) string { - words := splitAtCaseChangeWithTitlecase(word) - return strings.Join(words, "") -} - -func splitAtCaseChangeWithTitlecase(s string) []string { - words := make([]string, 0) - word := make([]rune, 0) - for _, c := range s { - spacer := isSpacerChar(c) - if len(word) > 0 { - if unicode.IsUpper(c) || spacer { - words = append(words, string(word)) - word = make([]rune, 0) - } - } - if !spacer { - if len(word) > 0 { - word = append(word, unicode.ToLower(c)) - } else { - word = append(word, unicode.ToUpper(c)) - } - } - } - words = append(words, string(word)) - return words -} - -func isSpacerChar(c rune) bool { - switch { - case c == rune("_"[0]): - return true - case c == rune(" "[0]): - return true - case c == rune(":"[0]): - return true - case c == rune("-"[0]): - return true - } - return false -} diff --git a/plugins/grpc/protoc-gen-php-grpc/php/ns.go b/plugins/grpc/protoc-gen-php-grpc/php/ns.go deleted file mode 100644 index c1dc3898..00000000 --- a/plugins/grpc/protoc-gen-php-grpc/php/ns.go +++ /dev/null @@ -1,103 +0,0 @@ -package php - -import ( - "bytes" - "fmt" - "strings" - - desc "google.golang.org/protobuf/types/descriptorpb" - plugin "google.golang.org/protobuf/types/pluginpb" -) - -// manages internal name representation of the package -type ns struct { - // Package defines file package. - Package string - - // Root namespace of the package - Namespace string - - // Import declares what namespaces to be imported - Import map[string]string -} - -// newNamespace creates new work namespace. -func newNamespace(req *plugin.CodeGeneratorRequest, file *desc.FileDescriptorProto, service *desc.ServiceDescriptorProto) *ns { - ns := &ns{ - Package: *file.Package, - Namespace: namespace(file.Package, "\\"), - Import: make(map[string]string), - } - - if file.Options != nil && file.Options.PhpNamespace != nil { - ns.Namespace = *file.Options.PhpNamespace - } - - for k := range service.Method { - ns.importMessage(req, service.Method[k].InputType) - ns.importMessage(req, service.Method[k].OutputType) - } - - return ns -} - -// importMessage registers new import message namespace (only the namespace). -func (ns *ns) importMessage(req *plugin.CodeGeneratorRequest, msg *string) { - if msg == nil { - return - } - - chunks := strings.Split(*msg, ".") - pkg := strings.Join(chunks[:len(chunks)-1], ".") - - result := bytes.NewBuffer(nil) - for _, p := range chunks[:len(chunks)-1] { - result.WriteString(identifier(p, "")) - result.WriteString(`\`) - } - - if pkg == "."+ns.Package { - // root package - return - } - - for _, f := range req.ProtoFile { - if pkg == "."+*f.Package { - if f.Options != nil && f.Options.PhpNamespace != nil { - // custom imported namespace - ns.Import[pkg] = *f.Options.PhpNamespace - return - } - } - } - - ns.Import[pkg] = strings.Trim(result.String(), `\`) -} - -// resolve message alias -func (ns *ns) resolve(msg *string) string { - chunks := strings.Split(*msg, ".") - pkg := strings.Join(chunks[:len(chunks)-1], ".") - - if pkg == "."+ns.Package { - // root message - return identifier(chunks[len(chunks)-1], "") - } - - for iPkg, ns := range ns.Import { - if pkg == iPkg { - // use last namespace chunk - nsChunks := strings.Split(ns, `\`) - identifier := identifier(chunks[len(chunks)-1], "") - - return fmt.Sprintf( - `%s\%s`, - nsChunks[len(nsChunks)-1], - resolveReserved(identifier, pkg), - ) - } - } - - // fully clarified name (fallback) - return "\\" + namespace(msg, "\\") -} diff --git a/plugins/grpc/protoc-gen-php-grpc/php/template.go b/plugins/grpc/protoc-gen-php-grpc/php/template.go deleted file mode 100644 index e00c6fdd..00000000 --- a/plugins/grpc/protoc-gen-php-grpc/php/template.go +++ /dev/null @@ -1,103 +0,0 @@ -// MIT License -// -// Copyright (c) 2018 SpiralScout -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package php - -import ( - "bytes" - "fmt" - "strings" - "text/template" - - desc "google.golang.org/protobuf/types/descriptorpb" - plugin "google.golang.org/protobuf/types/pluginpb" -) - -const phpBody = ` "DinoParty" +func Camelize(word string) string { + words := splitAtCaseChangeWithTitlecase(word) + return strings.Join(words, "") +} + +func splitAtCaseChangeWithTitlecase(s string) []string { + words := make([]string, 0) + word := make([]rune, 0) + for _, c := range s { + spacer := isSpacerChar(c) + if len(word) > 0 { + if unicode.IsUpper(c) || spacer { + words = append(words, string(word)) + word = make([]rune, 0) + } + } + if !spacer { + if len(word) > 0 { + word = append(word, unicode.ToLower(c)) + } else { + word = append(word, unicode.ToUpper(c)) + } + } + } + words = append(words, string(word)) + return words +} + +func isSpacerChar(c rune) bool { + switch { + case c == rune("_"[0]): + return true + case c == rune(" "[0]): + return true + case c == rune(":"[0]): + return true + case c == rune("-"[0]): + return true + } + return false +} diff --git a/plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/ns.go b/plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/ns.go new file mode 100644 index 00000000..c1dc3898 --- /dev/null +++ b/plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/ns.go @@ -0,0 +1,103 @@ +package php + +import ( + "bytes" + "fmt" + "strings" + + desc "google.golang.org/protobuf/types/descriptorpb" + plugin "google.golang.org/protobuf/types/pluginpb" +) + +// manages internal name representation of the package +type ns struct { + // Package defines file package. + Package string + + // Root namespace of the package + Namespace string + + // Import declares what namespaces to be imported + Import map[string]string +} + +// newNamespace creates new work namespace. +func newNamespace(req *plugin.CodeGeneratorRequest, file *desc.FileDescriptorProto, service *desc.ServiceDescriptorProto) *ns { + ns := &ns{ + Package: *file.Package, + Namespace: namespace(file.Package, "\\"), + Import: make(map[string]string), + } + + if file.Options != nil && file.Options.PhpNamespace != nil { + ns.Namespace = *file.Options.PhpNamespace + } + + for k := range service.Method { + ns.importMessage(req, service.Method[k].InputType) + ns.importMessage(req, service.Method[k].OutputType) + } + + return ns +} + +// importMessage registers new import message namespace (only the namespace). +func (ns *ns) importMessage(req *plugin.CodeGeneratorRequest, msg *string) { + if msg == nil { + return + } + + chunks := strings.Split(*msg, ".") + pkg := strings.Join(chunks[:len(chunks)-1], ".") + + result := bytes.NewBuffer(nil) + for _, p := range chunks[:len(chunks)-1] { + result.WriteString(identifier(p, "")) + result.WriteString(`\`) + } + + if pkg == "."+ns.Package { + // root package + return + } + + for _, f := range req.ProtoFile { + if pkg == "."+*f.Package { + if f.Options != nil && f.Options.PhpNamespace != nil { + // custom imported namespace + ns.Import[pkg] = *f.Options.PhpNamespace + return + } + } + } + + ns.Import[pkg] = strings.Trim(result.String(), `\`) +} + +// resolve message alias +func (ns *ns) resolve(msg *string) string { + chunks := strings.Split(*msg, ".") + pkg := strings.Join(chunks[:len(chunks)-1], ".") + + if pkg == "."+ns.Package { + // root message + return identifier(chunks[len(chunks)-1], "") + } + + for iPkg, ns := range ns.Import { + if pkg == iPkg { + // use last namespace chunk + nsChunks := strings.Split(ns, `\`) + identifier := identifier(chunks[len(chunks)-1], "") + + return fmt.Sprintf( + `%s\%s`, + nsChunks[len(nsChunks)-1], + resolveReserved(identifier, pkg), + ) + } + } + + // fully clarified name (fallback) + return "\\" + namespace(msg, "\\") +} diff --git a/plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/template.go b/plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/template.go new file mode 100644 index 00000000..e00c6fdd --- /dev/null +++ b/plugins/grpc/protoc_plugins/protoc-gen-php-grpc/php/template.go @@ -0,0 +1,103 @@ +// MIT License +// +// Copyright (c) 2018 SpiralScout +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package php + +import ( + "bytes" + "fmt" + "strings" + "text/template" + + desc "google.golang.org/protobuf/types/descriptorpb" + plugin "google.golang.org/protobuf/types/pluginpb" +) + +const phpBody = `