2 Star 6 Fork 5

Plato/rpc-go-backend

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
testcaller_impl.go 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
CloudGuan 提交于 2023-10-10 20:57 +08:00 . !16ISSUE: async rpc call result
// Generated by the go idl tools. DO NOT EDIT 2022-03-17 11:27:42
// source: box_example
package example
import (
"gitee.com/dennis-kk/rpc-go-backend/idlrpc"
"time"
)
type testSubInfo struct {
subID string
event string
byte []byte
}
type TestCallerImpl struct {
name string
subInfo []*testSubInfo
}
func (sp *TestCallerImpl) OnSubscribe(subID string, event string, bytes []byte) error {
sp.subInfo = append(sp.subInfo, &testSubInfo{
subID: subID,
event: event,
byte: bytes,
})
return nil
}
func (sp *TestCallerImpl) OnCancel(subID string, event string) error {
if sp.subInfo[0].subID == subID && sp.subInfo[0].event == event {
sp.subInfo = nil
}
return nil
}
func (sp *TestCallerImpl) testEventCallback(event string, data []byte) {
}
func NewTestCaller() *TestCallerImpl {
service := &TestCallerImpl{
subInfo: make([]*testSubInfo, 0, 10),
}
return service
}
func (sp *TestCallerImpl) GetUUID() uint64 {
return 6784101236246863201
}
func (sp *TestCallerImpl) GetNickName() string {
return "6784101236246863201"
}
func (sp *TestCallerImpl) OnAfterFork(ctx idlrpc.IServiceContext) bool {
//add this service to framework, do not call rpc method in this function
return true
}
func (sp *TestCallerImpl) OnTick() bool {
//tick function in main goroutine
return true
}
func (sp *TestCallerImpl) OnBeforeDestroy() bool {
//tick function in main goroutine
return true
}
func (sp *TestCallerImpl) SetInfo(ctx idlrpc.IServiceContext, option string) (err error) {
switch option {
case "timeout":
// 休眠一秒
time.Sleep(time.Second)
sp.name = option
default:
sp.name = option
}
return
}
func (sp *TestCallerImpl) GetInfo(ctx idlrpc.IServiceContext) (ret1 string, err error) {
// 设置不立即返回
ctx.Continue()
go func() {
// 休眠0.5秒,然后返回
time.Sleep(time.Millisecond * 300)
_ = ctx.Finish("return_plato", nil)
}()
return "", nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dennis-kk/rpc-go-backend.git
git@gitee.com:dennis-kk/rpc-go-backend.git
dennis-kk
rpc-go-backend
rpc-go-backend
v0.5.12

搜索帮助