Fetch the repository succeeded.
package node
import (
"gitee.com/monobytes/gcore/gcluster"
"gitee.com/monobytes/gcore/internal/transporter/internal/client"
"golang.org/x/sync/singleflight"
"sync"
)
type Options struct {
InsID string // 实例ID
InsKind gcluster.Kind // 实例类型
}
type Builder struct {
sfg singleflight.Group
opts *Options
clients sync.Map
}
func NewBuilder(opts *Options) *Builder {
return &Builder{
opts: opts,
}
}
// Build 构建客户端
func (b *Builder) Build(addr string) (*Client, error) {
if cli, ok := b.clients.Load(addr); ok {
return cli.(*Client), nil
}
cli, err, _ := b.sfg.Do(addr, func() (interface{}, error) {
cli := NewClient(client.NewClient(&client.Options{
Addr: addr,
InsID: b.opts.InsID,
InsKind: b.opts.InsKind,
CloseHandler: func() { b.clients.Delete(addr) },
}))
b.clients.Store(addr, cli)
return cli, nil
})
if err != nil {
return nil, err
}
return cli.(*Client), nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。