mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
431 lines
11 KiB
Go
431 lines
11 KiB
Go
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
|
|
|
package demo
|
|
|
|
import (
|
|
tls "crypto/tls"
|
|
gob "encoding/gob"
|
|
fmt "fmt"
|
|
reflect "reflect"
|
|
strings "strings"
|
|
time "time"
|
|
|
|
gotsrpc "github.com/foomo/gotsrpc/v2"
|
|
github_com_foomo_gotsrpc_v2_demo_nested "github.com/foomo/gotsrpc/v2/demo/nested"
|
|
gorpc "github.com/valyala/gorpc"
|
|
)
|
|
|
|
type (
|
|
FooGoRPCProxy struct {
|
|
server *gorpc.Server
|
|
service *Foo
|
|
callStatsHandler gotsrpc.GoRPCCallStatsHandlerFun
|
|
}
|
|
|
|
FooHelloRequest struct {
|
|
Number int64
|
|
}
|
|
FooHelloResponse struct {
|
|
RetHello_0 int
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
gob.Register(FooHelloRequest{})
|
|
gob.Register(FooHelloResponse{})
|
|
}
|
|
|
|
func NewFooGoRPCProxy(addr string, service *Foo, tlsConfig *tls.Config) *FooGoRPCProxy {
|
|
proxy := &FooGoRPCProxy{
|
|
service: service,
|
|
}
|
|
|
|
if tlsConfig != nil {
|
|
proxy.server = gorpc.NewTLSServer(addr, proxy.handler, tlsConfig)
|
|
} else {
|
|
proxy.server = gorpc.NewTCPServer(addr, proxy.handler)
|
|
}
|
|
|
|
return proxy
|
|
}
|
|
|
|
func (p *FooGoRPCProxy) Start() error {
|
|
return p.server.Start()
|
|
}
|
|
|
|
func (p *FooGoRPCProxy) Serve() error {
|
|
return p.server.Serve()
|
|
}
|
|
|
|
func (p *FooGoRPCProxy) Stop() {
|
|
p.server.Stop()
|
|
}
|
|
|
|
func (p *FooGoRPCProxy) SetCallStatsHandler(handler gotsrpc.GoRPCCallStatsHandlerFun) {
|
|
p.callStatsHandler = handler
|
|
}
|
|
|
|
func (p *FooGoRPCProxy) handler(clientAddr string, request interface{}) (response interface{}) {
|
|
start := time.Now()
|
|
|
|
reqType := reflect.TypeOf(request).String()
|
|
funcNameParts := strings.Split(reqType, ".")
|
|
funcName := funcNameParts[len(funcNameParts)-1]
|
|
|
|
switch funcName {
|
|
case "FooHelloRequest":
|
|
req := request.(FooHelloRequest)
|
|
retHello_0 := p.service.Hello(req.Number)
|
|
response = FooHelloResponse{RetHello_0: retHello_0}
|
|
default:
|
|
fmt.Println("Unkown request type", reflect.TypeOf(request).String())
|
|
}
|
|
|
|
if p.callStatsHandler != nil {
|
|
p.callStatsHandler(&gotsrpc.CallStats{
|
|
Func: funcName,
|
|
Package: "github.com/foomo/gotsrpc/v2/demo",
|
|
Service: "Foo",
|
|
Execution: time.Since(start),
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type (
|
|
DemoGoRPCProxy struct {
|
|
server *gorpc.Server
|
|
service *Demo
|
|
callStatsHandler gotsrpc.GoRPCCallStatsHandlerFun
|
|
}
|
|
|
|
DemoAnyRequest struct {
|
|
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
|
|
}
|
|
DemoAnyResponse struct {
|
|
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
|
|
}
|
|
|
|
DemoExtractAddressRequest struct {
|
|
Person *Person
|
|
}
|
|
DemoExtractAddressResponse struct {
|
|
Addr *Address
|
|
E *Err
|
|
}
|
|
|
|
DemoGiveMeAScalarRequest struct {
|
|
}
|
|
DemoGiveMeAScalarResponse struct {
|
|
Amount github_com_foomo_gotsrpc_v2_demo_nested.Amount
|
|
Wahr github_com_foomo_gotsrpc_v2_demo_nested.True
|
|
Hier ScalarInPlace
|
|
}
|
|
|
|
DemoHelloRequest struct {
|
|
Name string
|
|
}
|
|
DemoHelloResponse struct {
|
|
RetHello_0 string
|
|
RetHello_1 *Err
|
|
}
|
|
|
|
DemoHelloInterfaceRequest struct {
|
|
Anything interface{}
|
|
AnythingMap map[string]interface{}
|
|
AnythingSlice []interface{}
|
|
}
|
|
DemoHelloInterfaceResponse struct {
|
|
}
|
|
|
|
DemoHelloNumberMapsRequest struct {
|
|
IntMap map[int]string
|
|
}
|
|
DemoHelloNumberMapsResponse struct {
|
|
FloatMap map[float64]string
|
|
}
|
|
|
|
DemoHelloScalarErrorRequest struct {
|
|
}
|
|
DemoHelloScalarErrorResponse struct {
|
|
Err *ScalarError
|
|
}
|
|
|
|
DemoMapCrapRequest struct {
|
|
}
|
|
DemoMapCrapResponse struct {
|
|
Crap map[string][]int
|
|
}
|
|
|
|
DemoNestRequest struct {
|
|
}
|
|
DemoNestResponse struct {
|
|
RetNest_0 []*github_com_foomo_gotsrpc_v2_demo_nested.Nested
|
|
}
|
|
|
|
DemoTestScalarInPlaceRequest struct {
|
|
}
|
|
DemoTestScalarInPlaceResponse struct {
|
|
RetTestScalarInPlace_0 ScalarInPlace
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
gob.Register(DemoAnyRequest{})
|
|
gob.Register(DemoAnyResponse{})
|
|
gob.Register(DemoExtractAddressRequest{})
|
|
gob.Register(DemoExtractAddressResponse{})
|
|
gob.Register(DemoGiveMeAScalarRequest{})
|
|
gob.Register(DemoGiveMeAScalarResponse{})
|
|
gob.Register(DemoHelloRequest{})
|
|
gob.Register(DemoHelloResponse{})
|
|
gob.Register(DemoHelloInterfaceRequest{})
|
|
gob.Register(DemoHelloInterfaceResponse{})
|
|
gob.Register(DemoHelloNumberMapsRequest{})
|
|
gob.Register(DemoHelloNumberMapsResponse{})
|
|
gob.Register(DemoHelloScalarErrorRequest{})
|
|
gob.Register(DemoHelloScalarErrorResponse{})
|
|
gob.Register(DemoMapCrapRequest{})
|
|
gob.Register(DemoMapCrapResponse{})
|
|
gob.Register(DemoNestRequest{})
|
|
gob.Register(DemoNestResponse{})
|
|
gob.Register(DemoTestScalarInPlaceRequest{})
|
|
gob.Register(DemoTestScalarInPlaceResponse{})
|
|
}
|
|
|
|
func NewDemoGoRPCProxy(addr string, service *Demo, tlsConfig *tls.Config) *DemoGoRPCProxy {
|
|
proxy := &DemoGoRPCProxy{
|
|
service: service,
|
|
}
|
|
|
|
if tlsConfig != nil {
|
|
proxy.server = gorpc.NewTLSServer(addr, proxy.handler, tlsConfig)
|
|
} else {
|
|
proxy.server = gorpc.NewTCPServer(addr, proxy.handler)
|
|
}
|
|
|
|
return proxy
|
|
}
|
|
|
|
func (p *DemoGoRPCProxy) Start() error {
|
|
return p.server.Start()
|
|
}
|
|
|
|
func (p *DemoGoRPCProxy) Serve() error {
|
|
return p.server.Serve()
|
|
}
|
|
|
|
func (p *DemoGoRPCProxy) Stop() {
|
|
p.server.Stop()
|
|
}
|
|
|
|
func (p *DemoGoRPCProxy) SetCallStatsHandler(handler gotsrpc.GoRPCCallStatsHandlerFun) {
|
|
p.callStatsHandler = handler
|
|
}
|
|
|
|
func (p *DemoGoRPCProxy) handler(clientAddr string, request interface{}) (response interface{}) {
|
|
start := time.Now()
|
|
|
|
reqType := reflect.TypeOf(request).String()
|
|
funcNameParts := strings.Split(reqType, ".")
|
|
funcName := funcNameParts[len(funcNameParts)-1]
|
|
|
|
switch funcName {
|
|
case "DemoAnyRequest":
|
|
req := request.(DemoAnyRequest)
|
|
retAny_0, retAny_1, retAny_2 := p.service.Any(req.Any, req.AnyList, req.AnyMap)
|
|
response = DemoAnyResponse{RetAny_0: retAny_0, RetAny_1: retAny_1, RetAny_2: retAny_2}
|
|
case "DemoExtractAddressRequest":
|
|
req := request.(DemoExtractAddressRequest)
|
|
addr, e := p.service.ExtractAddress(req.Person)
|
|
response = DemoExtractAddressResponse{Addr: addr, E: e}
|
|
case "DemoGiveMeAScalarRequest":
|
|
amount, wahr, hier := p.service.GiveMeAScalar()
|
|
response = DemoGiveMeAScalarResponse{Amount: amount, Wahr: wahr, Hier: hier}
|
|
case "DemoHelloRequest":
|
|
req := request.(DemoHelloRequest)
|
|
retHello_0, retHello_1 := p.service.Hello(req.Name)
|
|
response = DemoHelloResponse{RetHello_0: retHello_0, RetHello_1: retHello_1}
|
|
case "DemoHelloInterfaceRequest":
|
|
req := request.(DemoHelloInterfaceRequest)
|
|
p.service.HelloInterface(req.Anything, req.AnythingMap, req.AnythingSlice)
|
|
response = DemoHelloInterfaceResponse{}
|
|
case "DemoHelloNumberMapsRequest":
|
|
req := request.(DemoHelloNumberMapsRequest)
|
|
floatMap := p.service.HelloNumberMaps(req.IntMap)
|
|
response = DemoHelloNumberMapsResponse{FloatMap: floatMap}
|
|
case "DemoHelloScalarErrorRequest":
|
|
err := p.service.HelloScalarError()
|
|
response = DemoHelloScalarErrorResponse{Err: err}
|
|
case "DemoMapCrapRequest":
|
|
crap := p.service.MapCrap()
|
|
response = DemoMapCrapResponse{Crap: crap}
|
|
case "DemoNestRequest":
|
|
retNest_0 := p.service.Nest()
|
|
response = DemoNestResponse{RetNest_0: retNest_0}
|
|
case "DemoTestScalarInPlaceRequest":
|
|
retTestScalarInPlace_0 := p.service.TestScalarInPlace()
|
|
response = DemoTestScalarInPlaceResponse{RetTestScalarInPlace_0: retTestScalarInPlace_0}
|
|
default:
|
|
fmt.Println("Unkown request type", reflect.TypeOf(request).String())
|
|
}
|
|
|
|
if p.callStatsHandler != nil {
|
|
p.callStatsHandler(&gotsrpc.CallStats{
|
|
Func: funcName,
|
|
Package: "github.com/foomo/gotsrpc/v2/demo",
|
|
Service: "Demo",
|
|
Execution: time.Since(start),
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type (
|
|
BarGoRPCProxy struct {
|
|
server *gorpc.Server
|
|
service Bar
|
|
callStatsHandler gotsrpc.GoRPCCallStatsHandlerFun
|
|
}
|
|
|
|
BarCustomErrorRequest struct {
|
|
One CustomError
|
|
Two *CustomError
|
|
}
|
|
BarCustomErrorResponse struct {
|
|
Three CustomError
|
|
Four *CustomError
|
|
}
|
|
|
|
BarCustomTypeRequest struct {
|
|
CustomTypeInt CustomTypeInt
|
|
CustomTypeString CustomTypeString
|
|
CustomTypeStruct CustomTypeStruct
|
|
}
|
|
BarCustomTypeResponse struct {
|
|
RetCustomType_0 *CustomTypeInt
|
|
RetCustomType_1 *CustomTypeString
|
|
RetCustomType_2 CustomTypeStruct
|
|
}
|
|
|
|
BarHelloRequest struct {
|
|
Number int64
|
|
}
|
|
BarHelloResponse struct {
|
|
RetHello_0 int
|
|
}
|
|
|
|
BarInheritanceRequest struct {
|
|
Inner Inner
|
|
Nested OuterNested
|
|
Inline OuterInline
|
|
}
|
|
BarInheritanceResponse struct {
|
|
RetInheritance_0 Inner
|
|
RetInheritance_1 OuterNested
|
|
RetInheritance_2 OuterInline
|
|
}
|
|
|
|
BarRepeatRequest struct {
|
|
One string
|
|
Two string
|
|
}
|
|
BarRepeatResponse struct {
|
|
Three bool
|
|
Four bool
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
gob.Register(BarCustomErrorRequest{})
|
|
gob.Register(BarCustomErrorResponse{})
|
|
gob.Register(BarCustomTypeRequest{})
|
|
gob.Register(BarCustomTypeResponse{})
|
|
gob.Register(BarHelloRequest{})
|
|
gob.Register(BarHelloResponse{})
|
|
gob.Register(BarInheritanceRequest{})
|
|
gob.Register(BarInheritanceResponse{})
|
|
gob.Register(BarRepeatRequest{})
|
|
gob.Register(BarRepeatResponse{})
|
|
}
|
|
|
|
func NewBarGoRPCProxy(addr string, service Bar, tlsConfig *tls.Config) *BarGoRPCProxy {
|
|
proxy := &BarGoRPCProxy{
|
|
service: service,
|
|
}
|
|
|
|
if tlsConfig != nil {
|
|
proxy.server = gorpc.NewTLSServer(addr, proxy.handler, tlsConfig)
|
|
} else {
|
|
proxy.server = gorpc.NewTCPServer(addr, proxy.handler)
|
|
}
|
|
|
|
return proxy
|
|
}
|
|
|
|
func (p *BarGoRPCProxy) Start() error {
|
|
return p.server.Start()
|
|
}
|
|
|
|
func (p *BarGoRPCProxy) Serve() error {
|
|
return p.server.Serve()
|
|
}
|
|
|
|
func (p *BarGoRPCProxy) Stop() {
|
|
p.server.Stop()
|
|
}
|
|
|
|
func (p *BarGoRPCProxy) SetCallStatsHandler(handler gotsrpc.GoRPCCallStatsHandlerFun) {
|
|
p.callStatsHandler = handler
|
|
}
|
|
|
|
func (p *BarGoRPCProxy) handler(clientAddr string, request interface{}) (response interface{}) {
|
|
start := time.Now()
|
|
|
|
reqType := reflect.TypeOf(request).String()
|
|
funcNameParts := strings.Split(reqType, ".")
|
|
funcName := funcNameParts[len(funcNameParts)-1]
|
|
|
|
switch funcName {
|
|
case "BarCustomErrorRequest":
|
|
req := request.(BarCustomErrorRequest)
|
|
three, four := p.service.CustomError(req.One, req.Two)
|
|
response = BarCustomErrorResponse{Three: three, Four: four}
|
|
case "BarCustomTypeRequest":
|
|
req := request.(BarCustomTypeRequest)
|
|
retCustomType_0, retCustomType_1, retCustomType_2 := p.service.CustomType(req.CustomTypeInt, req.CustomTypeString, req.CustomTypeStruct)
|
|
response = BarCustomTypeResponse{RetCustomType_0: retCustomType_0, RetCustomType_1: retCustomType_1, RetCustomType_2: retCustomType_2}
|
|
case "BarHelloRequest":
|
|
req := request.(BarHelloRequest)
|
|
retHello_0 := p.service.Hello(nil, nil, req.Number)
|
|
response = BarHelloResponse{RetHello_0: retHello_0}
|
|
case "BarInheritanceRequest":
|
|
req := request.(BarInheritanceRequest)
|
|
retInheritance_0, retInheritance_1, retInheritance_2 := p.service.Inheritance(req.Inner, req.Nested, req.Inline)
|
|
response = BarInheritanceResponse{RetInheritance_0: retInheritance_0, RetInheritance_1: retInheritance_1, RetInheritance_2: retInheritance_2}
|
|
case "BarRepeatRequest":
|
|
req := request.(BarRepeatRequest)
|
|
three, four := p.service.Repeat(req.One, req.Two)
|
|
response = BarRepeatResponse{Three: three, Four: four}
|
|
default:
|
|
fmt.Println("Unkown request type", reflect.TypeOf(request).String())
|
|
}
|
|
|
|
if p.callStatsHandler != nil {
|
|
p.callStatsHandler(&gotsrpc.CallStats{
|
|
Func: funcName,
|
|
Package: "github.com/foomo/gotsrpc/v2/demo",
|
|
Service: "Bar",
|
|
Execution: time.Since(start),
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|