1 Star 0 Fork 0

micro-tools/micro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
session.go 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
545403892 提交于 2023-06-05 23:58 +08:00 . init
package base
import (
"context"
"fmt"
"gitee.com/micro-tools/micro/module"
"gitee.com/micro-tools/wf/extend/utils/ggrpc"
"gitee.com/micro-tools/wf/extend/utils/gmicro/registry"
"google.golang.org/grpc"
)
type serverSession struct {
node *registry.Node
name string
client *grpc.ClientConn
app module.App
}
// NewServerSession 创建一个节点实例
func NewServerSession(app module.App, name string, node *registry.Node) (module.ServerSession, error) {
var err error
session := &serverSession{
name: name,
node: node,
app: app,
}
cli := ggrpc.Client{
Name: app.Options().Tracing.Name,
Config: ggrpc.ClientConfig{
Address: fmt.Sprintf("%s:%d", node.Address, node.Port),
AutoClose: false,
Timeout: -1,
Tracing: app.Options().Tracing.Status,
},
Client: nil,
}
err = cli.NewClient(func(conn *grpc.ClientConn, ctx context.Context) (err error) {
session.client = conn
return nil
})
return session, err
}
func (c *serverSession) GetID() string {
return c.node.Id
}
func (c *serverSession) GetName() string {
return c.name
}
func (c *serverSession) GetClient() *grpc.ClientConn {
return c.client
}
//func (c *serverSession) GetRPC() wurpc.RPCClient {
// return c.rpc
//}
func (c *serverSession) GetApp() module.App {
return c.app
}
func (c *serverSession) GetNode() *registry.Node {
return c.node
}
func (c *serverSession) SetNode(node *registry.Node) (err error) {
c.node = node
return
}
/**
消息请求
*/
func (c *serverSession) Call(serviceName string, fnc func(*grpc.ClientConn, context.Context)) error {
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/micro-tools/micro.git
git@gitee.com:micro-tools/micro.git
micro-tools
micro
micro
v1.0.2

搜索帮助