4 Star 5 Fork 4

Plato / Service-Box-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
box_context.go 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
张宇 提交于 2023-09-08 07:18 . !20update:context提供debug日志
package sbox
import (
"gitee.com/dennis-kk/rpc-go-backend/idlrpc"
"gitee.com/dennis-kk/rpc-go-backend/idlrpc/pkg/transport"
)
type (
//ServiceBoxContext service-box context
ServiceBoxContext struct {
*idlrpc.RpcContext
trans *BoxChannel // 消息管道
box *ServiceBox // box实例
}
)
func NewServiceBoxContext(box *ServiceBox) *ServiceBoxContext {
return &ServiceBoxContext{
RpcContext: &idlrpc.RpcContext{},
trans: nil,
box: box,
}
}
func (c *ServiceBoxContext) GetServiceBox() *ServiceBox {
return c.box
}
func (c *ServiceBoxContext) GetTransport() transport.ITransport {
return c.trans
}
func (c *ServiceBoxContext) GetIdentityID() string {
if c.trans == nil {
return ""
}
return c.trans.IdentityID()
}
func (c *ServiceBoxContext) GetIdentityTag() string {
if c.trans == nil {
return ""
}
return c.trans.IdentityTag()
}
func (c *ServiceBoxContext) GetProxyFromPeer(uuid uint64) idlrpc.IProxy {
if c.box == nil {
return nil
}
if peer, err := c.box.GetProxyFromPeer(c, uuid); err != nil {
c.box.logger.Error("Obtaining the peer Proxy failed, error: %s", err.Error())
return nil
} else {
return peer
}
}
func (c *ServiceBoxContext) GetProxy(uuid uint64) idlrpc.IProxy {
if c.box == nil {
return nil
}
if proxy, err := c.box.GetProxy(uuid); err != nil {
c.box.logger.Error("Obtaining the proxy %d failed, error: %s", uuid, err.Error())
return nil
} else {
return proxy
}
}
func (c *ServiceBoxContext) GetProxyWithNickname(uuid uint64, name string) idlrpc.IProxy {
if c.box == nil {
return nil
}
if proxy, err := c.box.GetProxyWithNickName(uuid, name); err != nil {
c.box.logger.Error("Obtaining the proxy %d failed, error: %s", uuid, err.Error())
return nil
} else {
return proxy
}
}
func (c *ServiceBoxContext) Debug(format string, i ...interface{}) {
c.box.logger.Debug(format, i...)
}
func (c *ServiceBoxContext) Info(format string, i ...interface{}) {
c.box.logger.Info(format, i...)
}
func (c *ServiceBoxContext) Warning(format string, i ...interface{}) {
c.box.logger.Warn(format, i...)
}
func (c *ServiceBoxContext) Error(format string, i ...interface{}) {
c.box.logger.Error(format, i...)
}
// Clone clone 一个新的上下文,保留连接,身份信息但是不保留global index 和 用户协议的中间态
func (c *ServiceBoxContext) Clone() idlrpc.IServiceContext {
return &ServiceBoxContext{
RpcContext: c.RpcContext.Clone(),
trans: c.trans,
box: c.box,
}
}
func (c *ServiceBoxContext) setBoxChannel(trans *BoxChannel) {
c.trans = trans
}
马建仓 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