代码拉取完成,页面将自动刷新
package discover
import (
"context"
"time"
"github.com/lukeaxu/discover/registry"
"google.golang.org/grpc/resolver"
)
type grpcResolver struct {
cc resolver.ClientConn
registry registry.Registry
target resolver.Target
timeout time.Duration // 解析的最大延迟
close chan struct{}
}
func (g *grpcResolver) ResolveNow(resolver.ResolveNowOptions) {
g.resolveNow()
}
func (g *grpcResolver) resolveNow() {
ctx, cancel := context.WithTimeout(context.Background(), g.timeout)
defer cancel()
services, err := g.registry.ListServices(ctx, g.target.Endpoint())
if err != nil {
g.cc.ReportError(err)
return
}
addresses := make([]resolver.Address, len(services))
for i, service := range services {
addresses[i] = resolver.Address{
Addr: service.Addr,
}
}
err = g.cc.UpdateState(resolver.State{Addresses: addresses})
if err != nil {
g.cc.ReportError(err)
return
}
}
func (g *grpcResolver) Close() {
close(g.close)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。