gotsrpc/example/nullable/service/gorpc_gen.go
2022-08-17 08:48:21 +02:00

191 lines
4.6 KiB
Go

// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
package service
import (
tls "crypto/tls"
gob "encoding/gob"
fmt "fmt"
reflect "reflect"
strings "strings"
time "time"
gotsrpc "github.com/foomo/gotsrpc/v2"
gorpc "github.com/valyala/gorpc"
)
type (
ServiceGoRPCProxy struct {
server *gorpc.Server
service Service
callStatsHandler gotsrpc.GoRPCCallStatsHandlerFun
}
ServiceVariantARequest struct {
I1 Base
}
ServiceVariantAResponse struct {
R1 Base
}
ServiceVariantBRequest struct {
I1 BCustomType
}
ServiceVariantBResponse struct {
R1 BCustomType
}
ServiceVariantCRequest struct {
I1 BCustomTypes
}
ServiceVariantCResponse struct {
R1 BCustomTypes
}
ServiceVariantDRequest struct {
I1 BCustomTypesMap
}
ServiceVariantDResponse struct {
R1 BCustomTypesMap
}
ServiceVariantERequest struct {
I1 *Base
}
ServiceVariantEResponse struct {
R1 *Base
}
ServiceVariantFRequest struct {
I1 []*Base
}
ServiceVariantFResponse struct {
R1 []*Base
}
ServiceVariantGRequest struct {
I1 map[string]*Base
}
ServiceVariantGResponse struct {
R1 map[string]*Base
}
ServiceVariantHRequest struct {
I1 Base
I2 *Base
I3 []*Base
I4 map[string]Base
}
ServiceVariantHResponse struct {
R1 Base
R2 *Base
R3 []*Base
R4 map[string]Base
}
)
func init() {
gob.Register(ServiceVariantARequest{})
gob.Register(ServiceVariantAResponse{})
gob.Register(ServiceVariantBRequest{})
gob.Register(ServiceVariantBResponse{})
gob.Register(ServiceVariantCRequest{})
gob.Register(ServiceVariantCResponse{})
gob.Register(ServiceVariantDRequest{})
gob.Register(ServiceVariantDResponse{})
gob.Register(ServiceVariantERequest{})
gob.Register(ServiceVariantEResponse{})
gob.Register(ServiceVariantFRequest{})
gob.Register(ServiceVariantFResponse{})
gob.Register(ServiceVariantGRequest{})
gob.Register(ServiceVariantGResponse{})
gob.Register(ServiceVariantHRequest{})
gob.Register(ServiceVariantHResponse{})
}
func NewServiceGoRPCProxy(addr string, service Service, tlsConfig *tls.Config) *ServiceGoRPCProxy {
proxy := &ServiceGoRPCProxy{
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 *ServiceGoRPCProxy) Start() error {
return p.server.Start()
}
func (p *ServiceGoRPCProxy) Serve() error {
return p.server.Serve()
}
func (p *ServiceGoRPCProxy) Stop() {
p.server.Stop()
}
func (p *ServiceGoRPCProxy) SetCallStatsHandler(handler gotsrpc.GoRPCCallStatsHandlerFun) {
p.callStatsHandler = handler
}
func (p *ServiceGoRPCProxy) 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 "ServiceVariantARequest":
req := request.(ServiceVariantARequest)
r1 := p.service.VariantA(nil, nil, req.I1)
response = ServiceVariantAResponse{R1: r1}
case "ServiceVariantBRequest":
req := request.(ServiceVariantBRequest)
r1 := p.service.VariantB(nil, nil, req.I1)
response = ServiceVariantBResponse{R1: r1}
case "ServiceVariantCRequest":
req := request.(ServiceVariantCRequest)
r1 := p.service.VariantC(nil, nil, req.I1)
response = ServiceVariantCResponse{R1: r1}
case "ServiceVariantDRequest":
req := request.(ServiceVariantDRequest)
r1 := p.service.VariantD(nil, nil, req.I1)
response = ServiceVariantDResponse{R1: r1}
case "ServiceVariantERequest":
req := request.(ServiceVariantERequest)
r1 := p.service.VariantE(nil, nil, req.I1)
response = ServiceVariantEResponse{R1: r1}
case "ServiceVariantFRequest":
req := request.(ServiceVariantFRequest)
r1 := p.service.VariantF(nil, nil, req.I1)
response = ServiceVariantFResponse{R1: r1}
case "ServiceVariantGRequest":
req := request.(ServiceVariantGRequest)
r1 := p.service.VariantG(nil, nil, req.I1)
response = ServiceVariantGResponse{R1: r1}
case "ServiceVariantHRequest":
req := request.(ServiceVariantHRequest)
r1, r2, r3, r4 := p.service.VariantH(nil, nil, req.I1, req.I2, req.I3, req.I4)
response = ServiceVariantHResponse{R1: r1, R2: r2, R3: r3, R4: r4}
default:
fmt.Println("Unknown request type", reflect.TypeOf(request).String())
}
if p.callStatsHandler != nil {
p.callStatsHandler(&gotsrpc.CallStats{
Func: funcName,
Package: "github.com/foomo/gotsrpc/v2/example/nullable/service",
Service: "Service",
Execution: time.Since(start),
})
}
return
}