made gorpc client public

This commit is contained in:
franklin 2017-03-20 13:39:26 +01:00
parent c78f00ba6c
commit 99830b9e50

15
go.go
View File

@ -632,7 +632,7 @@ func renderGoRPCServiceClients(services map[string]*Service, fullPackageName str
// Client type // Client type
g.l(` g.l(`
type ` + clientName + ` struct { type ` + clientName + ` struct {
client *gorpc.Client Client *gorpc.Client
} }
`) `)
// Constructor // Constructor
@ -640,20 +640,19 @@ func renderGoRPCServiceClients(services map[string]*Service, fullPackageName str
func New` + clientName + `(addr string, tlsConfig *tls.Config) *` + clientName + ` { func New` + clientName + `(addr string, tlsConfig *tls.Config) *` + clientName + ` {
client := &` + clientName + `{} client := &` + clientName + `{}
if tlsConfig == nil { if tlsConfig == nil {
client.client = gorpc.NewTCPClient(addr) client.Client = gorpc.NewTCPClient(addr)
} else { } else {
client.client = gorpc.NewTLSClient(addr, tlsConfig) client.Client = gorpc.NewTLSClient(addr, tlsConfig)
} }
client.Start()
return client return client
} }
func (c *` + clientName + `) Start() { func (c *` + clientName + `) Start() {
c.client.Start() c.Client.Start()
} }
func (c *` + clientName + `) Stop() { func (c *` + clientName + `) Stop() {
c.client.Stop() c.Client.Stop()
} }
`) `)
g.nl() g.nl()
@ -679,9 +678,9 @@ func renderGoRPCServiceClients(services map[string]*Service, fullPackageName str
g.l(`func (c *` + clientName + `) ` + method.Name + `(` + strings.Join(params, ", ") + `) (` + strings.Join(returns, ", ") + `) {`) g.l(`func (c *` + clientName + `) ` + method.Name + `(` + strings.Join(params, ", ") + `) (` + strings.Join(returns, ", ") + `) {`)
g.l(`req := ` + service.Name + method.Name + `Request{` + strings.Join(args, ", ") + `}`) g.l(`req := ` + service.Name + method.Name + `Request{` + strings.Join(args, ", ") + `}`)
if len(rets) > 0 { if len(rets) > 0 {
g.l(`rpcCallRes, rpcCallErr := c.client.Call(req)`) g.l(`rpcCallRes, rpcCallErr := c.Client.Call(req)`)
} else { } else {
g.l(`_, rpcCallErr := c.client.Call(req)`) g.l(`_, rpcCallErr := c.Client.Call(req)`)
} }
g.l(`if rpcCallErr != nil {`) g.l(`if rpcCallErr != nil {`)
g.l(`clientErr = rpcCallErr`) g.l(`clientErr = rpcCallErr`)