1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
resolver.go 959 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2022-08-28 17:55 . log
package resolver
import (
"gitee.com/h79/goutils/common/logger"
"gitee.com/h79/goutils/discovery/resolver/builder"
)
type Resolver interface {
Resolve(target builder.Target) []builder.Address
}
var _ builder.Resolver = (*Bridge)(nil)
type Bridge struct {
build Builder
target builder.Target
conn builder.Connector
}
// ResolveNow builder.Resolver interface
func (cr *Bridge) ResolveNow() {
logger.Info("Bridge: ResolveNow, target= '%v'", cr.target)
cr.update()
}
// Close builder.Resolver interface
func (cr *Bridge) Close() {
logger.Info("Bridge: Close, target= '%v'", cr.target)
}
func (cr *Bridge) update() {
if addrs := cr.build.Resolve(cr.target); len(addrs) > 0 {
cr.conn.UpdateState(builder.State{Addresses: addrs, Attributes: nil})
}
}
func NewResolver(target builder.Target, cc builder.Connector, builder Builder) builder.Resolver {
r := &Bridge{
target: target,
conn: cc,
build: builder,
}
r.update()
return r
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.8.35

搜索帮助