feat: add custom alias to gotsrpc client

This commit is contained in:
Stefan Martinov 2019-01-21 10:58:18 +01:00
parent b315d4e34b
commit b1b9a92ea1
2 changed files with 11 additions and 13 deletions

View File

@ -3,7 +3,7 @@
package demo
import (
http "net/http"
net_http "net/http"
gotsrpc "github.com/foomo/gotsrpc"
github_com_foomo_gotsrpc_demo_nested "github.com/foomo/gotsrpc/demo/nested"
@ -12,7 +12,7 @@ import (
type FooGoTSRPCClient interface {
Hello(number int64) (retHello_0 int, clientErr error)
SetClientEncoding(encoding gotsrpc.ClientEncoding)
SetTransportHttpClient(client *http.Client)
SetTransportHttpClient(client *net_http.Client)
}
type tsrpcFooGoTSRPCClient struct {
@ -29,7 +29,7 @@ func NewFooGoTSRPCClient(url string, endpoint string) FooGoTSRPCClient {
return NewFooGoTSRPCClientWithClient(url, "/service/foo", nil)
}
func NewFooGoTSRPCClientWithClient(url string, endpoint string, client *http.Client) FooGoTSRPCClient {
func NewFooGoTSRPCClientWithClient(url string, endpoint string, client *net_http.Client) FooGoTSRPCClient {
return &tsrpcFooGoTSRPCClient{
URL: url,
EndPoint: endpoint,
@ -41,7 +41,7 @@ func (tsc *tsrpcFooGoTSRPCClient) SetClientEncoding(encoding gotsrpc.ClientEncod
tsc.Client.SetClientEncoding(encoding)
}
func (tsc *tsrpcFooGoTSRPCClient) SetTransportHttpClient(client *http.Client) {
func (tsc *tsrpcFooGoTSRPCClient) SetTransportHttpClient(client *net_http.Client) {
tsc.Client.SetTransportHttpClient(client)
}
func (tsc *tsrpcFooGoTSRPCClient) Hello(number int64) (retHello_0 int, clientErr error) {
@ -61,7 +61,7 @@ type DemoGoTSRPCClient interface {
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)
SetTransportHttpClient(client *net_http.Client)
}
type tsrpcDemoGoTSRPCClient struct {
@ -78,7 +78,7 @@ func NewDemoGoTSRPCClient(url string, endpoint string) DemoGoTSRPCClient {
return NewDemoGoTSRPCClientWithClient(url, "/service/demo", nil)
}
func NewDemoGoTSRPCClientWithClient(url string, endpoint string, client *http.Client) DemoGoTSRPCClient {
func NewDemoGoTSRPCClientWithClient(url string, endpoint string, client *net_http.Client) DemoGoTSRPCClient {
return &tsrpcDemoGoTSRPCClient{
URL: url,
EndPoint: endpoint,
@ -90,7 +90,7 @@ func (tsc *tsrpcDemoGoTSRPCClient) SetClientEncoding(encoding gotsrpc.ClientEnco
tsc.Client.SetClientEncoding(encoding)
}
func (tsc *tsrpcDemoGoTSRPCClient) SetTransportHttpClient(client *http.Client) {
func (tsc *tsrpcDemoGoTSRPCClient) SetTransportHttpClient(client *net_http.Client) {
tsc.Client.SetTransportHttpClient(client)
}
func (tsc *tsrpcDemoGoTSRPCClient) ExtractAddress(person *Person) (addr *Address, e *Err, clientErr error) {

10
go.go
View File

@ -383,6 +383,7 @@ func (ms *goMethod) renderSignature() string {
func renderTSRPCServiceClients(services ServiceList, fullPackageName string, packageName string, config *config.Target, g *code) error {
aliases := map[string]string{
"github.com/foomo/gotsrpc": "gotsrpc",
"net/http": "net_http",
}
for _, service := range services {
@ -416,11 +417,8 @@ func renderTSRPCServiceClients(services ServiceList, fullPackageName string, pac
g.l(ms.renderSignature())
}
g.l(`SetClientEncoding(encoding gotsrpc.ClientEncoding)`)
g.l(`SetTransportHttpClient(client *http.Client) `)
g.l(`SetTransportHttpClient(client *net_http.Client) `)
g.l(`} `)
//Render Constructors
@ -439,7 +437,7 @@ func renderTSRPCServiceClients(services ServiceList, fullPackageName string, pac
return New` + interfaceName + `WithClient(url, "` + service.Endpoint + `", nil)
}
func New` + interfaceName + `WithClient(url string, endpoint string, client *http.Client) ` + interfaceName + ` {
func New` + interfaceName + `WithClient(url string, endpoint string, client *net_http.Client) ` + interfaceName + ` {
return &` + clientName + `{
URL: url,
EndPoint: endpoint,
@ -454,7 +452,7 @@ func renderTSRPCServiceClients(services ServiceList, fullPackageName string, pac
tsc.Client.SetClientEncoding(encoding)
}`)
g.l(`
func (tsc *` + clientName + `) SetTransportHttpClient(client *http.Client) {
func (tsc *` + clientName + `) SetTransportHttpClient(client *net_http.Client) {
tsc.Client.SetTransportHttpClient(client)
}`)