代码拉取完成,页面将自动刷新
package cRpc
import (
"fmt"
"sync"
)
const (
Header_Rpc_App = "Rpc-App"
Header_Rpc_Service = "Rpc-Service"
Header_Rpc_Method = "Rpc-Method"
)
type RpcServiceInterface interface {
RpcServiceName() (app string, service string)
}
type RpcContainer struct {
Lock *sync.Mutex
Instances map[string]interface{}
}
func (i *RpcContainer) Save(instance interface{}) {
i.Lock.Lock()
defer i.Lock.Unlock()
if IsRpcService(instance) {
app, service := instance.(RpcServiceInterface).RpcServiceName()
name := fmt.Sprintf("%s.%s", app, service)
i.Instances[name] = instance
}
}
func (i *RpcContainer) Get(app, service string) interface{} {
i.Lock.Lock()
defer i.Lock.Unlock()
name := fmt.Sprintf("%s.%s", app, service)
if _, ok := i.Instances[name]; ok {
return i.Instances[name]
}
return nil
}
var container = &RpcContainer{
Lock: &sync.Mutex{},
Instances: make(map[string]interface{}),
}
type RpcClientInterface interface {
RpcClientName() (app string, service string)
}
type RpcClientContainer struct {
Lock *sync.Mutex
Hosts map[string]string
}
func (i *RpcClientContainer) Save(client *RpcConf_Client) {
i.Lock.Lock()
defer i.Lock.Unlock()
if client == nil || len(client.Services) == 0 {
return
}
for _, service := range client.Services {
name := fmt.Sprintf("%s.%s", service.App, service.Service)
i.Hosts[name] = client.Host
}
}
func (i *RpcClientContainer) GetHost(app, service string) string {
i.Lock.Lock()
defer i.Lock.Unlock()
name := fmt.Sprintf("%s.%s", app, service)
if _, ok := i.Hosts[name]; ok {
return i.Hosts[name]
}
return ""
}
var clientContainer = &RpcClientContainer{
Lock: &sync.Mutex{},
Hosts: make(map[string]string),
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。