代码拉取完成,页面将自动刷新
package cRpc
import (
"fmt"
"reflect"
"sync"
"google.golang.org/grpc"
)
type RpcClientContainer struct {
lock sync.RWMutex
instances map[string]any
hosts map[string]string
grpc map[string]grpc.ClientConnInterface
}
func (i *RpcClientContainer) Save(instance any) bool {
i.lock.Lock()
defer i.lock.Unlock()
pkg, app, service := instance.(RpcClientInterface).RpcClientName()
index := pkg + "." + app + "." + service
i.instances[index] = instance
return true
}
func (i *RpcClientContainer) Get(name string) any {
i.lock.RLock()
defer i.lock.RUnlock()
return i.instances[name]
}
func (i *RpcClientContainer) Remove(name string) bool {
i.lock.Lock()
defer i.lock.Unlock()
delete(i.instances, name)
return true
}
func (i *RpcClientContainer) Is(instance any) bool {
return reflect.TypeOf(instance).Implements(reflect.TypeOf((*RpcServiceInterface)(nil)).Elem())
}
func (i *RpcClientContainer) Range(f func(instance any)) {
i.lock.RLock()
defer i.lock.RUnlock()
for _, item := range i.instances {
f(item)
}
}
func (i *RpcClientContainer) GetHost(pkg, app, name string) (host string) {
index := fmt.Sprintf("%s.%s.%s", pkg, app, name)
return i.hosts[index]
}
func (i *RpcClientContainer) GetGRPCConnection(pkg, app, name string) grpc.ClientConnInterface {
index := fmt.Sprintf("%s.%s.%s", pkg, app, name)
return i.grpc[index]
}
var client_container = &RpcClientContainer{
lock: sync.RWMutex{},
instances: make(map[string]any),
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。