4 Star 5 Fork 4

Plato / Service-Box-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
testcallee_proxy.go 13.03 KB
一键复制 编辑 原始数据 按行查看 历史
// Generated by the go idl tools. DO NOT EDIT 2023-06-02 11:56:54
// source: TestCallee
package testcallee
import (
"fmt"
"gitee.com/dennis-kk/rpc-go-backend/idlrpc"
"gitee.com/dennis-kk/rpc-go-backend/idlrpc/pkg/errors"
"gitee.com/dennis-kk/rpc-go-backend/idlrpc/pkg/protocol"
"gitee.com/dennis-kk/rpc-go-backend/idlrpc/pkg/transport"
"gitee.com/dennis-kk/service-box-go/example/idldata/pbdata"
"google.golang.org/protobuf/proto"
)
// TestCalleeProxy The service calls the proxy remotely
type TestCalleeProxy struct {
idlrpc.ProxyBase
}
func TestCalleeProxyCreator(trans transport.ITransport) idlrpc.IProxy {
if trans == nil {
return nil
}
if trans.IsClose() {
return nil
}
srvProxy := &TestCalleeProxy{}
srvProxy.SetTransport(trans)
return srvProxy
}
// GetUUID service's uuids
func (sp *TestCalleeProxy) GetUUID() uint64 {
return SrvUUID
}
func (sp *TestCalleeProxy) GetSrvName() string {
return SrvName
}
func (sp *TestCalleeProxy) GetSignature(methodIndex uint32) string {
var signature string
switch methodIndex {
case 1:
signature = "Add"
case 2:
signature = "Sub"
case 3:
signature = "SubPrivate"
case 4:
signature = "Divide"
}
return signature
}
func (sp *TestCalleeProxy) IsOneWay(methodId uint32) (isOneway bool) {
switch methodId {
case 1:
isOneway = false
case 2:
isOneway = false
case 3:
isOneway = false
case 4:
isOneway = false
default:
isOneway = false
}
return
}
func (sp *TestCalleeProxy) Add(ctx idlrpc.IServiceContext, _1 int32, _2 int32) (ret1 int32, err error) {
rpc := sp.GetRpc()
if rpc == nil {
//TODO add define error
return
}
pbarg := &pbdata.TestCallee_AddArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
respMsg, err := rpc.SyncCall(ctx, sp, 1, 500, 0, pbarg)
if err != nil && err != errors.ErrRpcRet {
return
}
//oneway 的方法 不用检测返回值序列化,相当于传统的调用
pbRet := &pbdata.TestCallee_AddRet{}
if perr := proto.Unmarshal(respMsg, pbRet); perr != nil {
err = perr
}
// 如果有上下文返回,则设置到ctx里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
ret1 = pbRet.Ret1
return
}
func (sp *TestCalleeProxy) AddAsync(ctx idlrpc.IServiceContext, _1 int32, _2 int32, cb AddCallBack) error {
rpc := sp.GetRpc()
if rpc == nil {
return nil
}
pbarg := &pbdata.TestCallee_AddArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
callBackWrapper := func(protoData []byte, errorCode uint32) {
var err error
// 声明返回值
var ret1 int32
pbRet := &pbdata.TestCallee_AddRet{}
if perr := proto.Unmarshal(protoData, pbRet); perr != nil {
cb(ret1, err)
return
}
// 如果有上下文返回,则设置到ctx里面,如果对端是返回错误,错误信息是在上下文里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
// 不是成功则直接触发错误
if errorCode != protocol.IDL_SUCCESS {
cb(ret1, idlrpc.RpcStrError(errorCode))
return
}
// 正常调用结束,反序列化返回值,从pb转换成model层数据
ret1 = pbRet.Ret1
// 调用call back
cb(ret1, err)
}
return rpc.AsyncCall(ctx, sp, 1, 500, 0, pbarg, callBackWrapper)
}
func (sp *TestCalleeProxy) Sub(ctx idlrpc.IServiceContext, _1 int32, _2 int32) (ret1 int32, err error) {
rpc := sp.GetRpc()
if rpc == nil {
//TODO add define error
return
}
pbarg := &pbdata.TestCallee_SubArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
respMsg, err := rpc.SyncCall(ctx, sp, 2, 10000, 0, pbarg)
if err != nil && err != errors.ErrRpcRet {
return
}
//oneway 的方法 不用检测返回值序列化,相当于传统的调用
pbRet := &pbdata.TestCallee_SubRet{}
if perr := proto.Unmarshal(respMsg, pbRet); perr != nil {
err = perr
}
// 如果有上下文返回,则设置到ctx里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
ret1 = pbRet.Ret1
return
}
func (sp *TestCalleeProxy) SubAsync(ctx idlrpc.IServiceContext, _1 int32, _2 int32, cb SubCallBack) error {
rpc := sp.GetRpc()
if rpc == nil {
return nil
}
pbarg := &pbdata.TestCallee_SubArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
callBackWrapper := func(protoData []byte, errorCode uint32) {
var err error
// 声明返回值
var ret1 int32
pbRet := &pbdata.TestCallee_SubRet{}
if perr := proto.Unmarshal(protoData, pbRet); perr != nil {
cb(ret1, err)
return
}
// 如果有上下文返回,则设置到ctx里面,如果对端是返回错误,错误信息是在上下文里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
// 不是成功则直接触发错误
if errorCode != protocol.IDL_SUCCESS {
cb(ret1, idlrpc.RpcStrError(errorCode))
return
}
// 正常调用结束,反序列化返回值,从pb转换成model层数据
ret1 = pbRet.Ret1
// 调用call back
cb(ret1, err)
}
return rpc.AsyncCall(ctx, sp, 2, 10000, 0, pbarg, callBackWrapper)
}
func (sp *TestCalleeProxy) SubPrivate(ctx idlrpc.IServiceContext, _1 int32, _2 int32) (ret1 int32, err error) {
rpc := sp.GetRpc()
if rpc == nil {
//TODO add define error
return
}
pbarg := &pbdata.TestCallee_SubPrivateArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
respMsg, err := rpc.SyncCall(ctx, sp, 3, 10000, 0, pbarg)
if err != nil && err != errors.ErrRpcRet {
return
}
//oneway 的方法 不用检测返回值序列化,相当于传统的调用
pbRet := &pbdata.TestCallee_SubPrivateRet{}
if perr := proto.Unmarshal(respMsg, pbRet); perr != nil {
err = perr
}
// 如果有上下文返回,则设置到ctx里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
ret1 = pbRet.Ret1
return
}
func (sp *TestCalleeProxy) SubPrivateAsync(ctx idlrpc.IServiceContext, _1 int32, _2 int32, cb SubPrivateCallBack) error {
rpc := sp.GetRpc()
if rpc == nil {
return nil
}
pbarg := &pbdata.TestCallee_SubPrivateArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
callBackWrapper := func(protoData []byte, errorCode uint32) {
var err error
// 声明返回值
var ret1 int32
pbRet := &pbdata.TestCallee_SubPrivateRet{}
if perr := proto.Unmarshal(protoData, pbRet); perr != nil {
cb(ret1, err)
return
}
// 如果有上下文返回,则设置到ctx里面,如果对端是返回错误,错误信息是在上下文里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
// 不是成功则直接触发错误
if errorCode != protocol.IDL_SUCCESS {
cb(ret1, idlrpc.RpcStrError(errorCode))
return
}
// 正常调用结束,反序列化返回值,从pb转换成model层数据
ret1 = pbRet.Ret1
// 调用call back
cb(ret1, err)
}
return rpc.AsyncCall(ctx, sp, 3, 10000, 0, pbarg, callBackWrapper)
}
func (sp *TestCalleeProxy) Divide(ctx idlrpc.IServiceContext, _1 int32, _2 int32) (ret1 int32, err error) {
rpc := sp.GetRpc()
if rpc == nil {
//TODO add define error
return
}
pbarg := &pbdata.TestCallee_DivideArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
respMsg, err := rpc.SyncCall(ctx, sp, 4, 10000, 0, pbarg)
if err != nil && err != errors.ErrRpcRet {
return
}
//oneway 的方法 不用检测返回值序列化,相当于传统的调用
pbRet := &pbdata.TestCallee_DivideRet{}
if perr := proto.Unmarshal(respMsg, pbRet); perr != nil {
err = perr
}
// 如果有上下文返回,则设置到ctx里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
ret1 = pbRet.Ret1
return
}
func (sp *TestCalleeProxy) DivideAsync(ctx idlrpc.IServiceContext, _1 int32, _2 int32, cb DivideCallBack) error {
rpc := sp.GetRpc()
if rpc == nil {
return nil
}
pbarg := &pbdata.TestCallee_DivideArgs{}
pbarg.Arg1 = _1
pbarg.Arg2 = _2
// 如果有用户自定义上下文,则穿透
kv := ctx.GetUserContext()
if kv != nil {
if pbarg.Ctx == nil {
pbarg.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbarg.Ctx.Info = append(pbarg.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
callBackWrapper := func(protoData []byte, errorCode uint32) {
var err error
// 声明返回值
var ret1 int32
pbRet := &pbdata.TestCallee_DivideRet{}
if perr := proto.Unmarshal(protoData, pbRet); perr != nil {
cb(ret1, err)
return
}
// 如果有上下文返回,则设置到ctx里面,如果对端是返回错误,错误信息是在上下文里面
if pbRet.Ctx != nil && pbRet.Ctx.Info != nil {
for _, kv := range pbRet.Ctx.Info {
if kv.Key == "error_info" {
err = fmt.Errorf("%w: %s", err, kv.Value)
} else if kv.Key == "call_trace" {
if sp.GetRpc().Options().CallTrace() {
panic(fmt.Sprintf("call trace =====> RPC CALL PANIC: \n%s\n<=====", kv.Value))
}
} else {
ctx.SetResponseContext(kv.Key, kv.Value)
}
}
}
// 不是成功则直接触发错误
if errorCode != protocol.IDL_SUCCESS {
cb(ret1, idlrpc.RpcStrError(errorCode))
return
}
// 正常调用结束,反序列化返回值,从pb转换成model层数据
ret1 = pbRet.Ret1
// 调用call back
cb(ret1, err)
}
return rpc.AsyncCall(ctx, sp, 4, 10000, 0, pbarg, callBackWrapper)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dennis-kk/service-box-go.git
git@gitee.com:dennis-kk/service-box-go.git
dennis-kk
service-box-go
Service-Box-go
v0.5.17

搜索帮助

344bd9b3 5694891 D2dac590 5694891