Skip to content
Snippets Groups Projects
Commit 172a4863 authored by amudong's avatar amudong
Browse files

fix: Code normalization

parent f740e576
No related branches found
No related tags found
No related merge requests found
...@@ -87,6 +87,7 @@ func ValidateNacosClient(container nacosClientFacade, opts ...Option) error { ...@@ -87,6 +87,7 @@ func ValidateNacosClient(container nacosClientFacade, opts ...Option) error {
split := strings.Split(nacosAddr, ":") split := strings.Split(nacosAddr, ":")
port, err := strconv.ParseUint(split[1], 10, 64) port, err := strconv.ParseUint(split[1], 10, 64)
if err != nil { if err != nil {
logger.Warnf("nacos addr port parse error ,error message is %v", err)
continue continue
} }
svrconf := nacosconst.ServerConfig{ svrconf := nacosconst.ServerConfig{
...@@ -99,10 +100,10 @@ func ValidateNacosClient(container nacosClientFacade, opts ...Option) error { ...@@ -99,10 +100,10 @@ func ValidateNacosClient(container nacosClientFacade, opts ...Option) error {
client, err := clients.CreateConfigClient(map[string]interface{}{ client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": svrConfList, "serverConfigs": svrConfList,
"clientConfig": nacosconst.ClientConfig{ "clientConfig": nacosconst.ClientConfig{
TimeoutMs: uint64(container.NacosClient().Timeout.Nanoseconds() / 1e6), TimeoutMs: uint64(container.NacosClient().Timeout.Milliseconds()),
ListenInterval: 10000, ListenInterval: 10000,
NotLoadCacheAtStart: true, NotLoadCacheAtStart: true,
LogDir: "logs/nacos/log", //TODO unified log directory LogDir: "logs/nacos/log",
}, },
}) })
container.NacosClient().Client = &client container.NacosClient().Client = &client
...@@ -143,10 +144,10 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N ...@@ -143,10 +144,10 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N
client, err := clients.CreateConfigClient(map[string]interface{}{ client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": svrConfList, "serverConfigs": svrConfList,
"clientConfig": nacosconst.ClientConfig{ "clientConfig": nacosconst.ClientConfig{
TimeoutMs: uint64(timeout.Nanoseconds() / 1e6), TimeoutMs: uint64(timeout.Milliseconds()),
ListenInterval: 20000, ListenInterval: 20000,
NotLoadCacheAtStart: true, NotLoadCacheAtStart: true,
LogDir: "logs/nacos/log", //TODO unified log directory LogDir: "logs/nacos/log",
}, },
}) })
n.Client = &client n.Client = &client
...@@ -157,49 +158,6 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N ...@@ -157,49 +158,6 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N
return n, nil return n, nil
} }
func newMockNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*NacosClient, error) {
var (
err error
n *NacosClient
)
n = &NacosClient{
name: name,
NacosAddrs: nacosAddrs,
Timeout: timeout,
exit: make(chan struct{}),
}
svrConfList := []nacosconst.ServerConfig{}
for _, nacosAddr := range n.NacosAddrs {
split := strings.Split(nacosAddr, ":")
port, err := strconv.ParseUint(split[1], 10, 64)
if err != nil {
continue
}
svrconf := nacosconst.ServerConfig{
IpAddr: split[0],
Port: port,
}
svrConfList = append(svrConfList, svrconf)
}
client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": svrConfList,
"clientConfig": nacosconst.ClientConfig{
TimeoutMs: uint64(timeout.Nanoseconds() / 1e6),
ListenInterval: 10000,
NotLoadCacheAtStart: true,
LogDir: "logs/nacos/log", ///TODO unified log directory
},
})
if err != nil {
return nil, perrors.WithMessagef(err, "nacos clients.CreateConfigClient(nacosAddrs:%+v)", nacosAddrs)
}
n.Client = &client
return n, nil
}
func (n *NacosClient) Done() <-chan struct{} { func (n *NacosClient) Done() <-chan struct{} {
return n.exit return n.exit
} }
...@@ -239,9 +197,7 @@ func (n *NacosClient) Close() { ...@@ -239,9 +197,7 @@ func (n *NacosClient) Close() {
n.stop() n.stop()
n.Lock() n.Lock()
if n.Client != nil { n.Client = nil
n.Client = nil
}
n.Unlock() n.Unlock()
logger.Warnf("nacosClient{name:%s, zk addr:%s} exit now.", n.name, n.NacosAddrs) logger.Warnf("nacosClient{name:%s, zk addr:%s} exit now.", n.name, n.NacosAddrs)
} }
...@@ -51,7 +51,6 @@ func newNacosDynamicConfiguration(url *common.URL) (*nacosDynamicConfiguration, ...@@ -51,7 +51,6 @@ func newNacosDynamicConfiguration(url *common.URL) (*nacosDynamicConfiguration,
c := &nacosDynamicConfiguration{ c := &nacosDynamicConfiguration{
rootPath: "/" + url.GetParam(constant.CONFIG_NAMESPACE_KEY, config_center.DEFAULT_GROUP) + "/config", rootPath: "/" + url.GetParam(constant.CONFIG_NAMESPACE_KEY, config_center.DEFAULT_GROUP) + "/config",
url: url, url: url,
keyListeners: sync.Map{},
} }
err := ValidateNacosClient(c, WithNacosName(NacosClientName)) err := ValidateNacosClient(c, WithNacosName(NacosClientName))
if err != nil { if err != nil {
...@@ -72,7 +71,7 @@ func (n *nacosDynamicConfiguration) RemoveListener(key string, listener config_c ...@@ -72,7 +71,7 @@ func (n *nacosDynamicConfiguration) RemoveListener(key string, listener config_c
n.removeListener(key, listener) n.removeListener(key, listener)
} }
//nacos group是dubbo DataId是key configfile 或 appconfigfile //nacos distinguishes configuration files based on group and dataId. defalut group = "dubbo" and dataId = key
func (n *nacosDynamicConfiguration) GetProperties(key string, opts ...config_center.Option) (string, error) { func (n *nacosDynamicConfiguration) GetProperties(key string, opts ...config_center.Option) (string, error) {
tmpOpts := &config_center.Options{} tmpOpts := &config_center.Options{}
......
...@@ -38,12 +38,10 @@ func (l *nacosDynamicConfiguration) addListener(key string, listener config_cent ...@@ -38,12 +38,10 @@ func (l *nacosDynamicConfiguration) addListener(key string, listener config_cent
_, loaded := l.keyListeners.Load(key) _, loaded := l.keyListeners.Load(key)
if !loaded { if !loaded {
_, cancel := context.WithCancel(context.Background()) _, cancel := context.WithCancel(context.Background())
(*l.client.Client).ListenConfig(vo.ConfigParam{ //TODO 这个listen接口应该要有个context的 (*l.client.Client).ListenConfig(vo.ConfigParam{
//(*l.client.Client).ListenConfigWithContext(ctx, vo.ConfigParam{
DataId: key, DataId: key,
Group: "dubbo", Group: "dubbo",
OnChange: func(namespace, group, dataId, data string) { OnChange: func(namespace, group, dataId, data string) {
//go callback(ctx, listener, namespace, group, dataId, data)
go callback(context.TODO(), listener, namespace, group, dataId, data) go callback(context.TODO(), listener, namespace, group, dataId, data)
}, },
}) })
...@@ -57,10 +55,4 @@ func (l *nacosDynamicConfiguration) addListener(key string, listener config_cent ...@@ -57,10 +55,4 @@ func (l *nacosDynamicConfiguration) addListener(key string, listener config_cent
func (l *nacosDynamicConfiguration) removeListener(key string, listener config_center.ConfigurationListener) { func (l *nacosDynamicConfiguration) removeListener(key string, listener config_center.ConfigurationListener) {
// TODO not supported in current go_nacos_sdk version // TODO not supported in current go_nacos_sdk version
//listeners, loaded := l.keyListeners.Load(key)
//if loaded {
// listenerMap := listeners.(map[config_center.ConfigurationListener]context.CancelFunc)
// listenerMap[listener]()
// delete(listeners.(map[config_center.ConfigurationListener]context.CancelFunc), listener)
//}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment