From 484a09bfa0786c8bbab417b297a652f255dec654 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Wed, 15 Nov 2017 17:00:35 -0800 Subject: [PATCH] mgrpc: fill out client generation functionality Signed-off-by: Stephen J Day --- generator.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/generator.go b/generator.go index 37f657b..633ff0f 100644 --- a/generator.go +++ b/generator.go @@ -1,6 +1,8 @@ package mgrpc import ( + "strings" + "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" "github.com/gogo/protobuf/protoc-gen-gogo/generator" ) @@ -76,15 +78,27 @@ func (p *mgrpcGenerator) genService(fullName string, service *descriptor.Service p.P("}") clientType := service.GetName() + "Client" + clientStructType := strings.ToLower(clientType[:1]) + clientType[1:] p.P() - p.P("type ", clientType, " struct{") + p.P("type ", clientStructType, " struct{") p.In() p.P("client *", p.mgrpcPkg.Use(), ".Client") p.Out() p.P("}") + p.P() + p.P("func New", clientType, "(client *", p.mgrpcPkg.Use(), ".Client)", serviceName, "{") + p.In() + p.P("return &", clientStructType, "{") + p.In() + p.P("client: client,") + p.Out() + p.P("}") + p.Out() + p.P("}") + p.P() for _, method := range service.Method { p.P() - p.P("func (c *", clientType, ") ", method.GetName(), + p.P("func (c *", clientStructType, ") ", method.GetName(), "(ctx ", p.contextPkg.Use(), ".Context, ", "req *", p.typeName(method.GetInputType()), ") ", "(*", p.typeName(method.GetOutputType()), ", error) {")