mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
feat: add context to go client
This commit is contained in:
parent
5e630c0631
commit
430911ed9d
11
client.go
11
client.go
@ -2,6 +2,7 @@ package gotsrpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -20,7 +21,7 @@ const (
|
|||||||
var _ Client = &bufferedClient{}
|
var _ Client = &bufferedClient{}
|
||||||
|
|
||||||
type Client interface {
|
type Client interface {
|
||||||
Call(url string, endpoint string, method string, args []interface{}, reply []interface{}) (err error)
|
Call(ctx context.Context, url string, endpoint string, method string, args []interface{}, reply []interface{}) (err error)
|
||||||
SetClientEncoding(encoding ClientEncoding)
|
SetClientEncoding(encoding ClientEncoding)
|
||||||
SetTransportHttpClient(client *http.Client)
|
SetTransportHttpClient(client *http.Client)
|
||||||
SetDefaultHeaders(headers http.Header)
|
SetDefaultHeaders(headers http.Header)
|
||||||
@ -38,11 +39,11 @@ func NewClientWithHttpClient(client *http.Client) Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRequest(url string, contentType string, buffer *bytes.Buffer, headers http.Header) (r *http.Request, err error) {
|
func newRequest(ctx context.Context, url string, contentType string, buffer *bytes.Buffer, headers http.Header) (r *http.Request, err error) {
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
buffer = &bytes.Buffer{}
|
buffer = &bytes.Buffer{}
|
||||||
}
|
}
|
||||||
request, errRequest := http.NewRequest("POST", url, buffer)
|
request, errRequest := http.NewRequestWithContext(ctx, "POST", url, buffer)
|
||||||
if errRequest != nil {
|
if errRequest != nil {
|
||||||
return nil, errors.Wrap(errRequest, "could not create a request")
|
return nil, errors.Wrap(errRequest, "could not create a request")
|
||||||
}
|
}
|
||||||
@ -75,7 +76,7 @@ func (c *bufferedClient) SetTransportHttpClient(client *http.Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CallClient calls a method on the remove service
|
// CallClient calls a method on the remove service
|
||||||
func (c *bufferedClient) Call(url string, endpoint string, method string, args []interface{}, reply []interface{}) (err error) {
|
func (c *bufferedClient) Call(ctx context.Context, url string, endpoint string, method string, args []interface{}, reply []interface{}) (err error) {
|
||||||
// Marshall args
|
// Marshall args
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ func (c *bufferedClient) Call(url string, endpoint string, method string, args [
|
|||||||
// Create post url
|
// Create post url
|
||||||
postURL := fmt.Sprintf("%s%s/%s", url, endpoint, method)
|
postURL := fmt.Sprintf("%s%s/%s", url, endpoint, method)
|
||||||
|
|
||||||
request, errRequest := newRequest(postURL, c.handle.contentType, b, c.headers.Clone())
|
request, errRequest := newRequest(ctx, postURL, c.handle.contentType, b, c.headers.Clone())
|
||||||
if errRequest != nil {
|
if errRequest != nil {
|
||||||
return errRequest
|
return errRequest
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package gotsrpc
|
package gotsrpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -12,12 +13,12 @@ func Test_newRequest(t *testing.T) {
|
|||||||
headers := http.Header{}
|
headers := http.Header{}
|
||||||
headers.Set("test", "test")
|
headers.Set("test", "test")
|
||||||
|
|
||||||
request, err := newRequest("/test", "text/html", nil, headers)
|
request, err := newRequest(context.Background(), "/test", "text/html", nil, headers)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "test", request.Header.Get("test"))
|
assert.Equal(t, "test", request.Header.Get("test"))
|
||||||
})
|
})
|
||||||
t.Run("default", func(t *testing.T) {
|
t.Run("default", func(t *testing.T) {
|
||||||
request, err := newRequest("/test", "text/html", nil, nil)
|
request, err := newRequest(context.Background(), "/test", "text/html", nil, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/test", request.URL.Path)
|
assert.Equal(t, "/test", request.URL.Path)
|
||||||
assert.Equal(t, "text/html", request.Header.Get("Accept"))
|
assert.Equal(t, "text/html", request.Header.Get("Accept"))
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Code generated by gotsrpc https://github.com/foomo/gotsrpc - DO NOT EDIT.
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
package demo
|
package demo
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Code generated by gotsrpc https://github.com/foomo/gotsrpc - DO NOT EDIT.
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
package demo
|
package demo
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Code generated by gotsrpc https://github.com/foomo/gotsrpc - DO NOT EDIT.
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
package demo
|
package demo
|
||||||
|
|
||||||
@ -42,7 +42,6 @@ func (p *FooGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer io.Copy(ioutil.Discard, r.Body) // Drain Request Body
|
defer io.Copy(ioutil.Discard, r.Body) // Drain Request Body
|
||||||
|
|
||||||
var args []interface{}
|
|
||||||
funcName := gotsrpc.GetCalledFunc(r, p.EndPoint)
|
funcName := gotsrpc.GetCalledFunc(r, p.EndPoint)
|
||||||
callStats := gotsrpc.GetStatsForRequest(r)
|
callStats := gotsrpc.GetStatsForRequest(r)
|
||||||
if callStats != nil {
|
if callStats != nil {
|
||||||
@ -55,7 +54,7 @@ func (p *FooGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var (
|
var (
|
||||||
arg_number int64
|
arg_number int64
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_number}
|
args := []interface{}{&arg_number}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -104,7 +103,6 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer io.Copy(ioutil.Discard, r.Body) // Drain Request Body
|
defer io.Copy(ioutil.Discard, r.Body) // Drain Request Body
|
||||||
|
|
||||||
var args []interface{}
|
|
||||||
funcName := gotsrpc.GetCalledFunc(r, p.EndPoint)
|
funcName := gotsrpc.GetCalledFunc(r, p.EndPoint)
|
||||||
callStats := gotsrpc.GetStatsForRequest(r)
|
callStats := gotsrpc.GetStatsForRequest(r)
|
||||||
if callStats != nil {
|
if callStats != nil {
|
||||||
@ -119,7 +117,7 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
arg_anyList []github_com_foomo_gotsrpc_v2_demo_nested.Any
|
arg_anyList []github_com_foomo_gotsrpc_v2_demo_nested.Any
|
||||||
arg_anyMap map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any
|
arg_anyMap map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_any, &arg_anyList, &arg_anyMap}
|
args := []interface{}{&arg_any, &arg_anyList, &arg_anyMap}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -136,7 +134,7 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var (
|
var (
|
||||||
arg_person *Person
|
arg_person *Person
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_person}
|
args := []interface{}{&arg_person}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -161,7 +159,7 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var (
|
var (
|
||||||
arg_name string
|
arg_name string
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_name}
|
args := []interface{}{&arg_name}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -180,7 +178,7 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
arg_anythingMap map[string]interface{}
|
arg_anythingMap map[string]interface{}
|
||||||
arg_anythingSlice []interface{}
|
arg_anythingSlice []interface{}
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_anything, &arg_anythingMap, &arg_anythingSlice}
|
args := []interface{}{&arg_anything, &arg_anythingMap, &arg_anythingSlice}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -197,7 +195,7 @@ func (p *DemoGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var (
|
var (
|
||||||
arg_intMap map[int]string
|
arg_intMap map[int]string
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_intMap}
|
args := []interface{}{&arg_intMap}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -278,7 +276,6 @@ func (p *BarGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer io.Copy(ioutil.Discard, r.Body) // Drain Request Body
|
defer io.Copy(ioutil.Discard, r.Body) // Drain Request Body
|
||||||
|
|
||||||
var args []interface{}
|
|
||||||
funcName := gotsrpc.GetCalledFunc(r, p.EndPoint)
|
funcName := gotsrpc.GetCalledFunc(r, p.EndPoint)
|
||||||
callStats := gotsrpc.GetStatsForRequest(r)
|
callStats := gotsrpc.GetStatsForRequest(r)
|
||||||
if callStats != nil {
|
if callStats != nil {
|
||||||
@ -292,7 +289,7 @@ func (p *BarGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
arg_one CustomError
|
arg_one CustomError
|
||||||
arg_two *CustomError
|
arg_two *CustomError
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_one, &arg_two}
|
args := []interface{}{&arg_one, &arg_two}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -311,7 +308,7 @@ func (p *BarGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
arg_customTypeString CustomTypeString
|
arg_customTypeString CustomTypeString
|
||||||
arg_CustomTypeStruct CustomTypeStruct
|
arg_CustomTypeStruct CustomTypeStruct
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_customTypeInt, &arg_customTypeString, &arg_CustomTypeStruct}
|
args := []interface{}{&arg_customTypeInt, &arg_customTypeString, &arg_CustomTypeStruct}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -328,7 +325,7 @@ func (p *BarGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var (
|
var (
|
||||||
arg_number int64
|
arg_number int64
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_number}
|
args := []interface{}{&arg_number}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -347,7 +344,7 @@ func (p *BarGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
arg_nested OuterNested
|
arg_nested OuterNested
|
||||||
arg_inline OuterInline
|
arg_inline OuterInline
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_inner, &arg_nested, &arg_inline}
|
args := []interface{}{&arg_inner, &arg_nested, &arg_inline}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
@ -365,7 +362,7 @@ func (p *BarGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
arg_one string
|
arg_one string
|
||||||
arg_two string
|
arg_two string
|
||||||
)
|
)
|
||||||
args = []interface{}{&arg_one, &arg_two}
|
args := []interface{}{&arg_one, &arg_two}
|
||||||
err := gotsrpc.LoadArgs(&args, callStats, r)
|
err := gotsrpc.LoadArgs(&args, callStats, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gotsrpc.ErrorCouldNotLoadArgs(w)
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
// Code generated by gotsrpc https://github.com/foomo/gotsrpc - DO NOT EDIT.
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
package demo
|
package demo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
net_http "net/http"
|
go_context "context"
|
||||||
|
go_net_http "net/http"
|
||||||
|
|
||||||
gotsrpc "github.com/foomo/gotsrpc/v2"
|
gotsrpc "github.com/foomo/gotsrpc/v2"
|
||||||
github_com_foomo_gotsrpc_v2_demo_nested "github.com/foomo/gotsrpc/v2/demo/nested"
|
github_com_foomo_gotsrpc_v2_demo_nested "github.com/foomo/gotsrpc/v2/demo/nested"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FooGoTSRPCClient interface {
|
type FooGoTSRPCClient interface {
|
||||||
Hello(number int64) (retHello_0 int, clientErr error)
|
Hello(ctx go_context.Context, number int64) (retHello_0 int, clientErr error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPFooGoTSRPCClient struct {
|
type HTTPFooGoTSRPCClient struct {
|
||||||
@ -27,31 +28,31 @@ func NewFooGoTSRPCClient(url string, endpoint string) *HTTPFooGoTSRPCClient {
|
|||||||
return NewFooGoTSRPCClientWithClient(url, endpoint, nil)
|
return NewFooGoTSRPCClientWithClient(url, endpoint, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFooGoTSRPCClientWithClient(url string, endpoint string, client *net_http.Client) *HTTPFooGoTSRPCClient {
|
func NewFooGoTSRPCClientWithClient(url string, endpoint string, client *go_net_http.Client) *HTTPFooGoTSRPCClient {
|
||||||
return &HTTPFooGoTSRPCClient{
|
return &HTTPFooGoTSRPCClient{
|
||||||
URL: url,
|
URL: url,
|
||||||
EndPoint: endpoint,
|
EndPoint: endpoint,
|
||||||
Client: gotsrpc.NewClientWithHttpClient(client),
|
Client: gotsrpc.NewClientWithHttpClient(client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (tsc *HTTPFooGoTSRPCClient) Hello(number int64) (retHello_0 int, clientErr error) {
|
func (tsc *HTTPFooGoTSRPCClient) Hello(ctx go_context.Context, number int64) (retHello_0 int, clientErr error) {
|
||||||
args := []interface{}{number}
|
args := []interface{}{number}
|
||||||
reply := []interface{}{&retHello_0}
|
reply := []interface{}{&retHello_0}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "Hello", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "Hello", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type DemoGoTSRPCClient interface {
|
type DemoGoTSRPCClient interface {
|
||||||
Any(any github_com_foomo_gotsrpc_v2_demo_nested.Any, anyList []github_com_foomo_gotsrpc_v2_demo_nested.Any, anyMap map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any) (retAny_0 github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_1 []github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_2 map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any, clientErr error)
|
Any(ctx go_context.Context, any github_com_foomo_gotsrpc_v2_demo_nested.Any, anyList []github_com_foomo_gotsrpc_v2_demo_nested.Any, anyMap map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any) (retAny_0 github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_1 []github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_2 map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any, clientErr error)
|
||||||
ExtractAddress(person *Person) (addr *Address, e *Err, clientErr error)
|
ExtractAddress(ctx go_context.Context, person *Person) (addr *Address, e *Err, clientErr error)
|
||||||
GiveMeAScalar() (amount github_com_foomo_gotsrpc_v2_demo_nested.Amount, wahr github_com_foomo_gotsrpc_v2_demo_nested.True, hier ScalarInPlace, clientErr error)
|
GiveMeAScalar(ctx go_context.Context) (amount github_com_foomo_gotsrpc_v2_demo_nested.Amount, wahr github_com_foomo_gotsrpc_v2_demo_nested.True, hier ScalarInPlace, clientErr error)
|
||||||
Hello(name string) (retHello_0 string, retHello_1 *Err, clientErr error)
|
Hello(ctx go_context.Context, name string) (retHello_0 string, retHello_1 *Err, clientErr error)
|
||||||
HelloInterface(anything interface{}, anythingMap map[string]interface{}, anythingSlice []interface{}) (clientErr error)
|
HelloInterface(ctx go_context.Context, anything interface{}, anythingMap map[string]interface{}, anythingSlice []interface{}) (clientErr error)
|
||||||
HelloNumberMaps(intMap map[int]string) (floatMap map[float64]string, clientErr error)
|
HelloNumberMaps(ctx go_context.Context, intMap map[int]string) (floatMap map[float64]string, clientErr error)
|
||||||
HelloScalarError() (err *ScalarError, clientErr error)
|
HelloScalarError(ctx go_context.Context) (err *ScalarError, clientErr error)
|
||||||
MapCrap() (crap map[string][]int, clientErr error)
|
MapCrap(ctx go_context.Context) (crap map[string][]int, clientErr error)
|
||||||
Nest() (retNest_0 []*github_com_foomo_gotsrpc_v2_demo_nested.Nested, clientErr error)
|
Nest(ctx go_context.Context) (retNest_0 []*github_com_foomo_gotsrpc_v2_demo_nested.Nested, clientErr error)
|
||||||
TestScalarInPlace() (retTestScalarInPlace_0 ScalarInPlace, clientErr error)
|
TestScalarInPlace(ctx go_context.Context) (retTestScalarInPlace_0 ScalarInPlace, clientErr error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPDemoGoTSRPCClient struct {
|
type HTTPDemoGoTSRPCClient struct {
|
||||||
@ -68,89 +69,89 @@ func NewDemoGoTSRPCClient(url string, endpoint string) *HTTPDemoGoTSRPCClient {
|
|||||||
return NewDemoGoTSRPCClientWithClient(url, endpoint, nil)
|
return NewDemoGoTSRPCClientWithClient(url, endpoint, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDemoGoTSRPCClientWithClient(url string, endpoint string, client *net_http.Client) *HTTPDemoGoTSRPCClient {
|
func NewDemoGoTSRPCClientWithClient(url string, endpoint string, client *go_net_http.Client) *HTTPDemoGoTSRPCClient {
|
||||||
return &HTTPDemoGoTSRPCClient{
|
return &HTTPDemoGoTSRPCClient{
|
||||||
URL: url,
|
URL: url,
|
||||||
EndPoint: endpoint,
|
EndPoint: endpoint,
|
||||||
Client: gotsrpc.NewClientWithHttpClient(client),
|
Client: gotsrpc.NewClientWithHttpClient(client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) Any(any github_com_foomo_gotsrpc_v2_demo_nested.Any, anyList []github_com_foomo_gotsrpc_v2_demo_nested.Any, anyMap map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any) (retAny_0 github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_1 []github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_2 map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) Any(ctx go_context.Context, any github_com_foomo_gotsrpc_v2_demo_nested.Any, anyList []github_com_foomo_gotsrpc_v2_demo_nested.Any, anyMap map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any) (retAny_0 github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_1 []github_com_foomo_gotsrpc_v2_demo_nested.Any, retAny_2 map[string]github_com_foomo_gotsrpc_v2_demo_nested.Any, clientErr error) {
|
||||||
args := []interface{}{any, anyList, anyMap}
|
args := []interface{}{any, anyList, anyMap}
|
||||||
reply := []interface{}{&retAny_0, &retAny_1, &retAny_2}
|
reply := []interface{}{&retAny_0, &retAny_1, &retAny_2}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "Any", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "Any", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) ExtractAddress(person *Person) (addr *Address, e *Err, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) ExtractAddress(ctx go_context.Context, person *Person) (addr *Address, e *Err, clientErr error) {
|
||||||
args := []interface{}{person}
|
args := []interface{}{person}
|
||||||
reply := []interface{}{&addr, &e}
|
reply := []interface{}{&addr, &e}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "ExtractAddress", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "ExtractAddress", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) GiveMeAScalar() (amount github_com_foomo_gotsrpc_v2_demo_nested.Amount, wahr github_com_foomo_gotsrpc_v2_demo_nested.True, hier ScalarInPlace, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) GiveMeAScalar(ctx go_context.Context) (amount github_com_foomo_gotsrpc_v2_demo_nested.Amount, wahr github_com_foomo_gotsrpc_v2_demo_nested.True, hier ScalarInPlace, clientErr error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
reply := []interface{}{&amount, &wahr, &hier}
|
reply := []interface{}{&amount, &wahr, &hier}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "GiveMeAScalar", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "GiveMeAScalar", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) Hello(name string) (retHello_0 string, retHello_1 *Err, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) Hello(ctx go_context.Context, name string) (retHello_0 string, retHello_1 *Err, clientErr error) {
|
||||||
args := []interface{}{name}
|
args := []interface{}{name}
|
||||||
reply := []interface{}{&retHello_0, &retHello_1}
|
reply := []interface{}{&retHello_0, &retHello_1}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "Hello", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "Hello", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) HelloInterface(anything interface{}, anythingMap map[string]interface{}, anythingSlice []interface{}) (clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) HelloInterface(ctx go_context.Context, anything interface{}, anythingMap map[string]interface{}, anythingSlice []interface{}) (clientErr error) {
|
||||||
args := []interface{}{anything, anythingMap, anythingSlice}
|
args := []interface{}{anything, anythingMap, anythingSlice}
|
||||||
reply := []interface{}{}
|
reply := []interface{}{}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "HelloInterface", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "HelloInterface", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) HelloNumberMaps(intMap map[int]string) (floatMap map[float64]string, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) HelloNumberMaps(ctx go_context.Context, intMap map[int]string) (floatMap map[float64]string, clientErr error) {
|
||||||
args := []interface{}{intMap}
|
args := []interface{}{intMap}
|
||||||
reply := []interface{}{&floatMap}
|
reply := []interface{}{&floatMap}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "HelloNumberMaps", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "HelloNumberMaps", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) HelloScalarError() (err *ScalarError, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) HelloScalarError(ctx go_context.Context) (err *ScalarError, clientErr error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
reply := []interface{}{&err}
|
reply := []interface{}{&err}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "HelloScalarError", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "HelloScalarError", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) MapCrap() (crap map[string][]int, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) MapCrap(ctx go_context.Context) (crap map[string][]int, clientErr error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
reply := []interface{}{&crap}
|
reply := []interface{}{&crap}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "MapCrap", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "MapCrap", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) Nest() (retNest_0 []*github_com_foomo_gotsrpc_v2_demo_nested.Nested, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) Nest(ctx go_context.Context) (retNest_0 []*github_com_foomo_gotsrpc_v2_demo_nested.Nested, clientErr error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
reply := []interface{}{&retNest_0}
|
reply := []interface{}{&retNest_0}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "Nest", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "Nest", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPDemoGoTSRPCClient) TestScalarInPlace() (retTestScalarInPlace_0 ScalarInPlace, clientErr error) {
|
func (tsc *HTTPDemoGoTSRPCClient) TestScalarInPlace(ctx go_context.Context) (retTestScalarInPlace_0 ScalarInPlace, clientErr error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
reply := []interface{}{&retTestScalarInPlace_0}
|
reply := []interface{}{&retTestScalarInPlace_0}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "TestScalarInPlace", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "TestScalarInPlace", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type BarGoTSRPCClient interface {
|
type BarGoTSRPCClient interface {
|
||||||
CustomError(one CustomError, two *CustomError) (three CustomError, four *CustomError, clientErr error)
|
CustomError(ctx go_context.Context, one CustomError, two *CustomError) (three CustomError, four *CustomError, clientErr error)
|
||||||
CustomType(customTypeInt CustomTypeInt, customTypeString CustomTypeString, CustomTypeStruct CustomTypeStruct) (retCustomType_0 *CustomTypeInt, retCustomType_1 *CustomTypeString, retCustomType_2 CustomTypeStruct, clientErr error)
|
CustomType(ctx go_context.Context, customTypeInt CustomTypeInt, customTypeString CustomTypeString, CustomTypeStruct CustomTypeStruct) (retCustomType_0 *CustomTypeInt, retCustomType_1 *CustomTypeString, retCustomType_2 CustomTypeStruct, clientErr error)
|
||||||
Hello(number int64) (retHello_0 int, clientErr error)
|
Hello(ctx go_context.Context, number int64) (retHello_0 int, clientErr error)
|
||||||
Inheritance(inner Inner, nested OuterNested, inline OuterInline) (retInheritance_0 Inner, retInheritance_1 OuterNested, retInheritance_2 OuterInline, clientErr error)
|
Inheritance(ctx go_context.Context, inner Inner, nested OuterNested, inline OuterInline) (retInheritance_0 Inner, retInheritance_1 OuterNested, retInheritance_2 OuterInline, clientErr error)
|
||||||
Repeat(one string, two string) (three bool, four bool, clientErr error)
|
Repeat(ctx go_context.Context, one string, two string) (three bool, four bool, clientErr error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPBarGoTSRPCClient struct {
|
type HTTPBarGoTSRPCClient struct {
|
||||||
@ -167,44 +168,44 @@ func NewBarGoTSRPCClient(url string, endpoint string) *HTTPBarGoTSRPCClient {
|
|||||||
return NewBarGoTSRPCClientWithClient(url, endpoint, nil)
|
return NewBarGoTSRPCClientWithClient(url, endpoint, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBarGoTSRPCClientWithClient(url string, endpoint string, client *net_http.Client) *HTTPBarGoTSRPCClient {
|
func NewBarGoTSRPCClientWithClient(url string, endpoint string, client *go_net_http.Client) *HTTPBarGoTSRPCClient {
|
||||||
return &HTTPBarGoTSRPCClient{
|
return &HTTPBarGoTSRPCClient{
|
||||||
URL: url,
|
URL: url,
|
||||||
EndPoint: endpoint,
|
EndPoint: endpoint,
|
||||||
Client: gotsrpc.NewClientWithHttpClient(client),
|
Client: gotsrpc.NewClientWithHttpClient(client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (tsc *HTTPBarGoTSRPCClient) CustomError(one CustomError, two *CustomError) (three CustomError, four *CustomError, clientErr error) {
|
func (tsc *HTTPBarGoTSRPCClient) CustomError(ctx go_context.Context, one CustomError, two *CustomError) (three CustomError, four *CustomError, clientErr error) {
|
||||||
args := []interface{}{one, two}
|
args := []interface{}{one, two}
|
||||||
reply := []interface{}{&three, &four}
|
reply := []interface{}{&three, &four}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "CustomError", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "CustomError", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPBarGoTSRPCClient) CustomType(customTypeInt CustomTypeInt, customTypeString CustomTypeString, CustomTypeStruct CustomTypeStruct) (retCustomType_0 *CustomTypeInt, retCustomType_1 *CustomTypeString, retCustomType_2 CustomTypeStruct, clientErr error) {
|
func (tsc *HTTPBarGoTSRPCClient) CustomType(ctx go_context.Context, customTypeInt CustomTypeInt, customTypeString CustomTypeString, CustomTypeStruct CustomTypeStruct) (retCustomType_0 *CustomTypeInt, retCustomType_1 *CustomTypeString, retCustomType_2 CustomTypeStruct, clientErr error) {
|
||||||
args := []interface{}{customTypeInt, customTypeString, CustomTypeStruct}
|
args := []interface{}{customTypeInt, customTypeString, CustomTypeStruct}
|
||||||
reply := []interface{}{&retCustomType_0, &retCustomType_1, &retCustomType_2}
|
reply := []interface{}{&retCustomType_0, &retCustomType_1, &retCustomType_2}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "CustomType", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "CustomType", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPBarGoTSRPCClient) Hello(number int64) (retHello_0 int, clientErr error) {
|
func (tsc *HTTPBarGoTSRPCClient) Hello(ctx go_context.Context, number int64) (retHello_0 int, clientErr error) {
|
||||||
args := []interface{}{number}
|
args := []interface{}{number}
|
||||||
reply := []interface{}{&retHello_0}
|
reply := []interface{}{&retHello_0}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "Hello", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "Hello", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPBarGoTSRPCClient) Inheritance(inner Inner, nested OuterNested, inline OuterInline) (retInheritance_0 Inner, retInheritance_1 OuterNested, retInheritance_2 OuterInline, clientErr error) {
|
func (tsc *HTTPBarGoTSRPCClient) Inheritance(ctx go_context.Context, inner Inner, nested OuterNested, inline OuterInline) (retInheritance_0 Inner, retInheritance_1 OuterNested, retInheritance_2 OuterInline, clientErr error) {
|
||||||
args := []interface{}{inner, nested, inline}
|
args := []interface{}{inner, nested, inline}
|
||||||
reply := []interface{}{&retInheritance_0, &retInheritance_1, &retInheritance_2}
|
reply := []interface{}{&retInheritance_0, &retInheritance_1, &retInheritance_2}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "Inheritance", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "Inheritance", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsc *HTTPBarGoTSRPCClient) Repeat(one string, two string) (three bool, four bool, clientErr error) {
|
func (tsc *HTTPBarGoTSRPCClient) Repeat(ctx go_context.Context, one string, two string) (three bool, four bool, clientErr error) {
|
||||||
args := []interface{}{one, two}
|
args := []interface{}{one, two}
|
||||||
reply := []interface{}{&three, &four}
|
reply := []interface{}{&three, &four}
|
||||||
clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "Repeat", args, reply)
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "Repeat", args, reply)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package demo
|
package demo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@ -9,8 +10,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/foomo/gotsrpc/v2/demo/nested"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/foomo/gotsrpc/v2/demo/nested"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -45,8 +47,9 @@ func teardown() {
|
|||||||
func TestDefault(t *testing.T) {
|
func TestDefault(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
resp, errServer, errClient := client.Hello("stefan")
|
resp, errServer, errClient := client.Hello(ctx, "stefan")
|
||||||
assert.NoError(t, errClient)
|
assert.NoError(t, errClient)
|
||||||
assert.Nil(t, errServer)
|
assert.Nil(t, errServer)
|
||||||
fmt.Println(resp)
|
fmt.Println(resp)
|
||||||
@ -55,8 +58,10 @@ func TestDefault(t *testing.T) {
|
|||||||
func TestHelloNumberMaps(t *testing.T) {
|
func TestHelloNumberMaps(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
intMap := map[int]string{1: "one", 2: "two", 3: "three"}
|
intMap := map[int]string{1: "one", 2: "two", 3: "three"}
|
||||||
floatMap, errClient := client.HelloNumberMaps(intMap)
|
floatMap, errClient := client.HelloNumberMaps(ctx, intMap)
|
||||||
assert.NoError(t, errClient)
|
assert.NoError(t, errClient)
|
||||||
for f, fstr := range floatMap {
|
for f, fstr := range floatMap {
|
||||||
i := int(f)
|
i := int(f)
|
||||||
@ -67,11 +72,12 @@ func TestHelloNumberMaps(t *testing.T) {
|
|||||||
func benchmarkRequests(b *testing.B, count int) {
|
func benchmarkRequests(b *testing.B, count int) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
person := GeneratePerson(count)
|
person := GeneratePerson(count)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
client.ExtractAddress(person)
|
client.ExtractAddress(ctx, person)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,21 +1,24 @@
|
|||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/foomo/gotsrpc/v2/demo"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/foomo/gotsrpc/v2/demo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHello(t *testing.T) {
|
func TestHello(t *testing.T) {
|
||||||
proxy := demo.NewDefaultBarGoTSRPCProxy(&Bar{})
|
proxy := demo.NewDefaultBarGoTSRPCProxy(&Bar{})
|
||||||
server := httptest.NewServer(proxy)
|
server := httptest.NewServer(proxy)
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
client := demo.NewDefaultBarGoTSRPCClient(server.URL)
|
client := demo.NewDefaultBarGoTSRPCClient(server.URL)
|
||||||
|
|
||||||
if res, clientErr := client.Hello(10); assert.NoError(t, clientErr) {
|
if res, clientErr := client.Hello(ctx, 10); assert.NoError(t, clientErr) {
|
||||||
assert.Equal(t, 10, res)
|
assert.Equal(t, 10, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,17 +27,18 @@ func TestCustomError(t *testing.T) {
|
|||||||
proxy := demo.NewDefaultBarGoTSRPCProxy(&Bar{})
|
proxy := demo.NewDefaultBarGoTSRPCProxy(&Bar{})
|
||||||
server := httptest.NewServer(proxy)
|
server := httptest.NewServer(proxy)
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
client := demo.NewDefaultBarGoTSRPCClient(server.URL)
|
client := demo.NewDefaultBarGoTSRPCClient(server.URL)
|
||||||
|
|
||||||
if three, four, clientErr := client.CustomError("", nil); assert.NoError(t, clientErr) {
|
if three, four, clientErr := client.CustomError(ctx, "", nil); assert.NoError(t, clientErr) {
|
||||||
assert.Equal(t, demo.CustomError(""), three)
|
assert.Equal(t, demo.CustomError(""), three)
|
||||||
assert.Nil(t, four)
|
assert.Nil(t, four)
|
||||||
}
|
}
|
||||||
|
|
||||||
one := demo.CustomErrorDemo
|
one := demo.CustomErrorDemo
|
||||||
two := demo.ErrCustomDemo
|
two := demo.ErrCustomDemo
|
||||||
if three, four, clientErr := client.CustomError(one, two); assert.NoError(t, clientErr) {
|
if three, four, clientErr := client.CustomError(ctx, one, two); assert.NoError(t, clientErr) {
|
||||||
assert.NotNil(t, three)
|
assert.NotNil(t, three)
|
||||||
assert.NotNil(t, four)
|
assert.NotNil(t, four)
|
||||||
assert.ErrorIs(t, demo.ErrCustomDemo, two)
|
assert.ErrorIs(t, demo.ErrCustomDemo, two)
|
||||||
|
|||||||
10
go.go
10
go.go
@ -347,6 +347,7 @@ type goMethod struct {
|
|||||||
func newMethodSignature(method *Method, aliases map[string]string, fullPackageName string) goMethod {
|
func newMethodSignature(method *Method, aliases map[string]string, fullPackageName string) goMethod {
|
||||||
var args []string
|
var args []string
|
||||||
var params []string
|
var params []string
|
||||||
|
params = append(params, "ctx go_context.Context")
|
||||||
for _, a := range goMethodArgsWithoutHTTPContextRelatedArgs(method) {
|
for _, a := range goMethodArgsWithoutHTTPContextRelatedArgs(method) {
|
||||||
args = append(args, a.Name)
|
args = append(args, a.Name)
|
||||||
params = append(params, a.Name+" "+a.Value.goType(aliases, fullPackageName))
|
params = append(params, a.Name+" "+a.Value.goType(aliases, fullPackageName))
|
||||||
@ -379,7 +380,8 @@ func (ms *goMethod) renderSignature() string {
|
|||||||
func renderTSRPCServiceClients(services ServiceList, fullPackageName string, packageName string, config *config.Target, g *code) error {
|
func renderTSRPCServiceClients(services ServiceList, fullPackageName string, packageName string, config *config.Target, g *code) error {
|
||||||
aliases := map[string]string{
|
aliases := map[string]string{
|
||||||
"github.com/foomo/gotsrpc/v2": "gotsrpc",
|
"github.com/foomo/gotsrpc/v2": "gotsrpc",
|
||||||
"net/http": "net_http",
|
"net/http": "go_net_http",
|
||||||
|
"context": "go_context",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
@ -431,7 +433,7 @@ func renderTSRPCServiceClients(services ServiceList, fullPackageName string, pac
|
|||||||
return New` + interfaceName + `WithClient(url, endpoint, nil)
|
return New` + interfaceName + `WithClient(url, endpoint, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New` + interfaceName + `WithClient(url string, endpoint string, client *net_http.Client) *` + clientName + ` {
|
func New` + interfaceName + `WithClient(url string, endpoint string, client *go_net_http.Client) *` + clientName + ` {
|
||||||
return &` + clientName + `{
|
return &` + clientName + `{
|
||||||
URL: url,
|
URL: url,
|
||||||
EndPoint: endpoint,
|
EndPoint: endpoint,
|
||||||
@ -444,7 +446,7 @@ func renderTSRPCServiceClients(services ServiceList, fullPackageName string, pac
|
|||||||
g.l(`func (tsc *` + clientName + `) ` + ms.renderSignature() + ` {`)
|
g.l(`func (tsc *` + clientName + `) ` + ms.renderSignature() + ` {`)
|
||||||
g.l(`args := []interface{}{` + strings.Join(ms.args, ", ") + `}`)
|
g.l(`args := []interface{}{` + strings.Join(ms.args, ", ") + `}`)
|
||||||
g.l(`reply := []interface{}{` + strings.Join(ms.rets, ", ") + `}`)
|
g.l(`reply := []interface{}{` + strings.Join(ms.rets, ", ") + `}`)
|
||||||
g.l(`clientErr = tsc.Client.Call(tsc.URL, tsc.EndPoint, "` + method.Name + `", args, reply)`)
|
g.l(`clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "` + method.Name + `", args, reply)`)
|
||||||
g.l(`return`)
|
g.l(`return`)
|
||||||
g.l(`}`)
|
g.l(`}`)
|
||||||
g.nl()
|
g.nl()
|
||||||
@ -778,7 +780,7 @@ func renderImports(aliases map[string]string, packageName string) string {
|
|||||||
imports += alias + " \"" + importPath + "\"\n"
|
imports += alias + " \"" + importPath + "\"\n"
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
// Code generated by gotsrpc https://github.com/foomo/gotsrpc - DO NOT EDIT.
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
package ` + packageName + `
|
package ` + packageName + `
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user