mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
feat: update generator to passthrough client encoding / transport client
This commit is contained in:
parent
8cee3c7df9
commit
8ae28037da
@ -18,8 +18,8 @@ var _ Client = &bufferedClient{}
|
||||
|
||||
type Client interface {
|
||||
Call(url string, endpoint string, method string, args []interface{}, reply []interface{}) (err error)
|
||||
SetEncoding(encoding ClientEncoding)
|
||||
SetHttpClient(client *http.Client)
|
||||
SetClientEncoding(encoding ClientEncoding)
|
||||
SetTransportHttpClient(client *http.Client)
|
||||
}
|
||||
|
||||
func NewClient() Client {
|
||||
@ -43,11 +43,11 @@ type bufferedClient struct {
|
||||
handle *clientHandle
|
||||
}
|
||||
|
||||
func (c *bufferedClient) SetEncoding(encoding ClientEncoding) {
|
||||
func (c *bufferedClient) SetClientEncoding(encoding ClientEncoding) {
|
||||
c.handle = getHandleForEncoding(encoding)
|
||||
}
|
||||
|
||||
func (c *bufferedClient) SetHttpClient(client *http.Client) {
|
||||
func (c *bufferedClient) SetTransportHttpClient(client *http.Client) {
|
||||
c.client = client
|
||||
}
|
||||
|
||||
|
||||
@ -3,12 +3,16 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
http "net/http"
|
||||
|
||||
gotsrpc "github.com/foomo/gotsrpc"
|
||||
github_com_foomo_gotsrpc_demo_nested "github.com/foomo/gotsrpc/demo/nested"
|
||||
)
|
||||
|
||||
type FooGoTSRPCClient interface {
|
||||
Hello(number int64) (retHello_0 int, clientErr error)
|
||||
SetClientEncoding(encoding gotsrpc.ClientEncoding)
|
||||
SetTransportHttpClient(client *http.Client)
|
||||
}
|
||||
|
||||
type tsrpcFooGoTSRPCClient struct {
|
||||
@ -29,8 +33,12 @@ func NewFooGoTSRPCClient(url string, endpoint string) FooGoTSRPCClient {
|
||||
}
|
||||
}
|
||||
|
||||
func (tsc *tsrpcFooGoTSRPCClient) SetClient(client gotsrpc.Client) {
|
||||
tsc.Client = client
|
||||
func (tsc *tsrpcFooGoTSRPCClient) SetClientEncoding(encoding gotsrpc.ClientEncoding) {
|
||||
tsc.Client.SetClientEncoding(encoding)
|
||||
}
|
||||
|
||||
func (tsc *tsrpcFooGoTSRPCClient) SetTransportHttpClient(client *http.Client) {
|
||||
tsc.Client.SetTransportHttpClient(client)
|
||||
}
|
||||
func (tsc *tsrpcFooGoTSRPCClient) Hello(number int64) (retHello_0 int, clientErr error) {
|
||||
args := []interface{}{number}
|
||||
@ -48,6 +56,8 @@ type DemoGoTSRPCClient interface {
|
||||
MapCrap() (crap map[string][]int, clientErr error)
|
||||
Nest() (retNest_0 []*github_com_foomo_gotsrpc_demo_nested.Nested, clientErr error)
|
||||
TestScalarInPlace() (retTestScalarInPlace_0 ScalarInPlace, clientErr error)
|
||||
SetClientEncoding(encoding gotsrpc.ClientEncoding)
|
||||
SetTransportHttpClient(client *http.Client)
|
||||
}
|
||||
|
||||
type tsrpcDemoGoTSRPCClient struct {
|
||||
@ -68,8 +78,12 @@ func NewDemoGoTSRPCClient(url string, endpoint string) DemoGoTSRPCClient {
|
||||
}
|
||||
}
|
||||
|
||||
func (tsc *tsrpcDemoGoTSRPCClient) SetClient(client gotsrpc.Client) {
|
||||
tsc.Client = client
|
||||
func (tsc *tsrpcDemoGoTSRPCClient) SetClientEncoding(encoding gotsrpc.ClientEncoding) {
|
||||
tsc.Client.SetClientEncoding(encoding)
|
||||
}
|
||||
|
||||
func (tsc *tsrpcDemoGoTSRPCClient) SetTransportHttpClient(client *http.Client) {
|
||||
tsc.Client.SetTransportHttpClient(client)
|
||||
}
|
||||
func (tsc *tsrpcDemoGoTSRPCClient) ExtractAddress(person *Person) (addr *Address, e *Err, clientErr error) {
|
||||
args := []interface{}{person}
|
||||
|
||||
18
go.go
18
go.go
@ -141,7 +141,7 @@ func extractImports(fields []*Field, fullPackageName string, aliases map[string]
|
||||
r := strings.NewReplacer(".", "_", "/", "_", "-", "_")
|
||||
|
||||
extractImport := func(packageName string) {
|
||||
if packageName!= fullPackageName {
|
||||
if packageName != fullPackageName {
|
||||
alias, ok := aliases[packageName]
|
||||
if !ok {
|
||||
packageParts := strings.Split(packageName, "/")
|
||||
@ -415,6 +415,12 @@ func renderTSRPCServiceClients(services ServiceList, fullPackageName string, pac
|
||||
ms := newMethodSignature(method, aliases, fullPackageName)
|
||||
g.l(ms.renderSignature())
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
g.l(`SetClientEncoding(encoding gotsrpc.ClientEncoding)`)
|
||||
g.l(`SetTransportHttpClient(client *http.Client) `)
|
||||
g.l(`} `)
|
||||
|
||||
//Render Constructors
|
||||
@ -436,11 +442,15 @@ func renderTSRPCServiceClients(services ServiceList, fullPackageName string, pac
|
||||
Client: gotsrpc.NewClient(),
|
||||
}
|
||||
}`)
|
||||
|
||||
//Render Methods
|
||||
|
||||
g.l(`
|
||||
func (tsc *` + clientName + `) SetClient(client gotsrpc.Client) {
|
||||
tsc.Client = client
|
||||
func (tsc *` + clientName + `) SetClientEncoding(encoding gotsrpc.ClientEncoding) {
|
||||
tsc.Client.SetClientEncoding(encoding)
|
||||
}`)
|
||||
g.l(`
|
||||
func (tsc *` + clientName + `) SetTransportHttpClient(client *http.Client) {
|
||||
tsc.Client.SetTransportHttpClient(client)
|
||||
}`)
|
||||
|
||||
for _, method := range service.Methods {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user