Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
172a4863
Commit
172a4863
authored
5 years ago
by
amudong
Browse files
Options
Downloads
Patches
Plain Diff
fix: Code normalization
parent
f740e576
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config_center/nacos/client.go
+6
-50
6 additions, 50 deletions
config_center/nacos/client.go
config_center/nacos/impl.go
+1
-2
1 addition, 2 deletions
config_center/nacos/impl.go
config_center/nacos/listener.go
+1
-9
1 addition, 9 deletions
config_center/nacos/listener.go
with
8 additions
and
61 deletions
config_center/nacos/client.go
+
6
−
50
View file @
172a4863
...
@@ -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
.
Nano
seconds
()
/
1e6
),
TimeoutMs
:
uint64
(
container
.
NacosClient
()
.
Timeout
.
Milli
seconds
()),
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
.
Nano
seconds
()
/
1e6
),
TimeoutMs
:
uint64
(
timeout
.
Milli
seconds
()),
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
)
}
}
This diff is collapsed.
Click to expand it.
config_center/nacos/impl.go
+
1
−
2
View file @
172a4863
...
@@ -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
{}
...
...
This diff is collapsed.
Click to expand it.
config_center/nacos/listener.go
+
1
−
9
View file @
172a4863
...
@@ -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)
//}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment