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

fix:gofmt nacos configcenter

parent 7f0decb3
No related branches found
No related tags found
No related merge requests found
......@@ -25,19 +25,19 @@ const (
)
type NacosClient struct {
name string
NacosAddrs []string
sync.Mutex // for Client
Client *config_client.IConfigClient
exit chan struct{}
Timeout time.Duration
name string
NacosAddrs []string
sync.Mutex // for Client
Client *config_client.IConfigClient
exit chan struct{}
Timeout time.Duration
}
type Option func(*Options)
type Options struct {
nacosName string
client *NacosClient
client *NacosClient
}
func WithNacosName(name string) Option {
......@@ -84,19 +84,19 @@ func ValidateNacosClient(container nacosClientFacade, opts ...Option) error {
if container.NacosClient().Client == nil {
svrConfList := []nacosconst.ServerConfig{}
for _, nacosAddr := range container.NacosClient().NacosAddrs {
split := strings.Split(nacosAddr,":")
split := strings.Split(nacosAddr, ":")
port, err := strconv.ParseUint(split[1], 10, 64)
if err != nil {
continue
}
svrconf := nacosconst.ServerConfig{
IpAddr: split[0],
Port: port,
Port: port,
}
svrConfList = append(svrConfList, svrconf)
}
client , err := clients.CreateConfigClient(map[string]interface{}{
client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": svrConfList,
"clientConfig": nacosconst.ClientConfig{
TimeoutMs: uint64(container.NacosClient().Timeout.Nanoseconds() / 1e6),
......@@ -116,31 +116,31 @@ func ValidateNacosClient(container nacosClientFacade, opts ...Option) error {
func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*NacosClient, error) {
var (
err error
n *NacosClient
err error
n *NacosClient
)
n = &NacosClient{
name: name,
NacosAddrs: nacosAddrs,
Timeout: timeout,
exit: make(chan struct{}),
name: name,
NacosAddrs: nacosAddrs,
Timeout: timeout,
exit: make(chan struct{}),
}
svrConfList := []nacosconst.ServerConfig{}
for _, nacosAddr := range n.NacosAddrs {
split := strings.Split(nacosAddr,":")
split := strings.Split(nacosAddr, ":")
port, err := strconv.ParseUint(split[1], 10, 64)
if err != nil {
continue
}
svrconf := nacosconst.ServerConfig{
IpAddr: split[0],
Port: port,
Port: port,
}
svrConfList = append(svrConfList, svrconf)
}
client , err := clients.CreateConfigClient(map[string]interface{}{
client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": svrConfList,
"clientConfig": nacosconst.ClientConfig{
TimeoutMs: uint64(timeout.Nanoseconds() / 1e6),
......@@ -159,32 +159,32 @@ func newNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*N
func newMockNacosClient(name string, nacosAddrs []string, timeout time.Duration) (*NacosClient, error) {
var (
err error
n *NacosClient
err error
n *NacosClient
)
n = &NacosClient{
name: name,
NacosAddrs: nacosAddrs,
Timeout: timeout,
exit: make(chan struct{}),
name: name,
NacosAddrs: nacosAddrs,
Timeout: timeout,
exit: make(chan struct{}),
}
svrConfList := []nacosconst.ServerConfig{}
for _, nacosAddr := range n.NacosAddrs {
split := strings.Split(nacosAddr,":")
split := strings.Split(nacosAddr, ":")
port, err := strconv.ParseUint(split[1], 10, 64)
if err != nil {
continue
}
svrconf := nacosconst.ServerConfig{
IpAddr: split[0],
Port: port,
Port: port,
}
svrConfList = append(svrConfList, svrconf)
}
client , err := clients.CreateConfigClient(map[string]interface{}{
client, err := clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": svrConfList,
"clientConfig": nacosconst.ClientConfig{
TimeoutMs: uint64(timeout.Nanoseconds() / 1e6),
......@@ -244,4 +244,4 @@ func (n *NacosClient) Close() {
}
n.Unlock()
logger.Warnf("nacosClient{name:%s, zk addr:%s} exit now.", n.name, n.NacosAddrs)
}
\ No newline at end of file
}
......@@ -94,5 +94,3 @@ LOOP:
}
}
}
......@@ -37,21 +37,21 @@ import (
const NacosClientName = "nacos config_center"
type nacosDynamicConfiguration struct {
url *common.URL
rootPath string
wg sync.WaitGroup
cltLock sync.Mutex
done chan struct{}
client *NacosClient
url *common.URL
rootPath string
wg sync.WaitGroup
cltLock sync.Mutex
done chan struct{}
client *NacosClient
keyListeners sync.Map
parser parser.ConfigurationParser
}
func newNacosDynamicConfiguration(url *common.URL) (*nacosDynamicConfiguration, error) {
c := &nacosDynamicConfiguration{
rootPath: "/" + url.GetParam(constant.CONFIG_NAMESPACE_KEY, config_center.DEFAULT_GROUP) + "/config",
url: url,
keyListeners:sync.Map{},
rootPath: "/" + url.GetParam(constant.CONFIG_NAMESPACE_KEY, config_center.DEFAULT_GROUP) + "/config",
url: url,
keyListeners: sync.Map{},
}
err := ValidateNacosClient(c, WithNacosName(NacosClientName))
if err != nil {
......@@ -80,8 +80,8 @@ func (n *nacosDynamicConfiguration) GetProperties(key string, opts ...config_cen
opt(tmpOpts)
}
content, err := (*n.client.Client).GetConfig(vo.ConfigParam{
DataId: key,
Group: tmpOpts.Group,
DataId: key,
Group: tmpOpts.Group,
})
if err != nil {
return "", perrors.WithStack(err)
......
......@@ -51,9 +51,9 @@ func initNacosData(t *testing.T) (*nacosDynamicConfiguration, error) {
dubbo.protocols.myDubbo.name=dubbo
`
sucess, err := (*nacosConfiguration.client.Client).PublishConfig(vo.ConfigParam{
DataId: "dubbo.properties",
Group: "dubbo",
Content: data,
DataId: "dubbo.properties",
Group: "dubbo",
Content: data,
})
assert.NoError(t, err)
if !sucess {
......@@ -86,9 +86,9 @@ func Test_AddListener(t *testing.T) {
dubbo.protocols.myDubbo.name=dubbo
`
sucess, err := (*nacos.client.Client).PublishConfig(vo.ConfigParam{
DataId: "dubbo.properties",
Group: "dubbo",
Content: data,
DataId: "dubbo.properties",
Group: "dubbo",
Content: data,
})
assert.NoError(t, err)
if !sucess {
......@@ -99,12 +99,12 @@ func Test_AddListener(t *testing.T) {
}
func Test_RemoveListener(t *testing.T) {
//TODO not supported in current go_nacos_sdk version
}
type mockDataListener struct {
wg sync.WaitGroup
wg sync.WaitGroup
event string
}
......@@ -112,4 +112,4 @@ func (l *mockDataListener) Process(configType *config_center.ConfigChangeEvent)
fmt.Println("process!!!!!!!!!!")
l.wg.Done()
l.event = configType.Key
}
\ No newline at end of file
}
......@@ -39,9 +39,9 @@ func (l *nacosDynamicConfiguration) addListener(key string, listener config_cent
if !loaded {
_, cancel := context.WithCancel(context.Background())
(*l.client.Client).ListenConfig(vo.ConfigParam{ //TODO 这个listen接口应该要有个context的
//(*l.client.Client).ListenConfigWithContext(ctx, vo.ConfigParam{
DataId: key,
Group: "dubbo",
//(*l.client.Client).ListenConfigWithContext(ctx, vo.ConfigParam{
DataId: key,
Group: "dubbo",
OnChange: func(namespace, group, dataId, data string) {
//go callback(ctx, listener, namespace, group, dataId, data)
go callback(context.TODO(), listener, namespace, group, dataId, data)
......
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