mgrpc: fill out client generation functionality

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-11-15 17:00:35 -08:00
parent 76ad1535fb
commit 484a09bfa0
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F

View File

@ -1,6 +1,8 @@
package mgrpc package mgrpc
import ( import (
"strings"
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor" "github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
"github.com/gogo/protobuf/protoc-gen-gogo/generator" "github.com/gogo/protobuf/protoc-gen-gogo/generator"
) )
@ -76,15 +78,27 @@ func (p *mgrpcGenerator) genService(fullName string, service *descriptor.Service
p.P("}") p.P("}")
clientType := service.GetName() + "Client" clientType := service.GetName() + "Client"
clientStructType := strings.ToLower(clientType[:1]) + clientType[1:]
p.P() p.P()
p.P("type ", clientType, " struct{") p.P("type ", clientStructType, " struct{")
p.In() p.In()
p.P("client *", p.mgrpcPkg.Use(), ".Client") p.P("client *", p.mgrpcPkg.Use(), ".Client")
p.Out() p.Out()
p.P("}") 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 { for _, method := range service.Method {
p.P() p.P()
p.P("func (c *", clientType, ") ", method.GetName(), p.P("func (c *", clientStructType, ") ", method.GetName(),
"(ctx ", p.contextPkg.Use(), ".Context, ", "(ctx ", p.contextPkg.Use(), ".Context, ",
"req *", p.typeName(method.GetInputType()), ") ", "req *", p.typeName(method.GetInputType()), ") ",
"(*", p.typeName(method.GetOutputType()), ", error) {") "(*", p.typeName(method.GetOutputType()), ", error) {")