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