1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
builder.go 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2022-08-28 17:55 . log
package thrift
import (
"fmt"
"gitee.com/h79/goutils/common/logger"
"gitee.com/h79/goutils/discovery/resolver/builder"
thriftresolver "gitee.com/h79/goutils/thrift/resolver"
)
// priBuilder 为thrift桥接
type priBuilder struct {
myBuilder builder.Builder
}
func Register(builder builder.Builder) {
b := &priBuilder{
myBuilder: builder,
}
// 注册到thrift中
thriftresolver.Register(b)
}
// Build grpc interface
func (cb *priBuilder) Build(target thriftresolver.Target, cc thriftresolver.Connector) (thriftresolver.Resolver, error) {
if cc == nil {
return nil, fmt.Errorf("[Thrift Build] client connect is nil")
}
logger.Debug("Thrift: Build target= %+v", target)
tar := builder.Target{
Scheme: target.Scheme,
Authority: target.Authority,
Endpoint: target.Endpoint,
}
cr := &connector{
cc: cc,
}
rr, err := cb.myBuilder.Build(tar, cr)
if err != nil {
return nil, err
}
rr0 := &priResolver{
myResolver: rr,
}
return rr0, nil
}
// Scheme thrift interface
func (cb *priBuilder) Scheme() string {
return cb.myBuilder.Scheme()
}
type priResolver struct {
myResolver builder.Resolver
}
// ResolveNow thrift.Resolver interface
func (cr *priResolver) ResolveNow() {
cr.myResolver.ResolveNow()
}
// Close thrift.Resolver interface
func (cr *priResolver) Close() {
cr.myResolver.Close()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.21.11

搜索帮助