Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
6889d2f0
Commit
6889d2f0
authored
May 29, 2021
by
zhaoyunxing92
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
up:代码优化
parent
ac643b25
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
24 deletions
+31
-24
client.go
database/kv/nacos/client.go
+31
-24
No files found.
database/kv/nacos/client.go
View file @
6889d2f0
...
...
@@ -57,44 +57,51 @@ func initNacosConfigClientPool() {
// NewNacosNamingClient create nacos client
func
NewNacosNamingClient
(
name
string
,
share
bool
,
sc
[]
constant
.
ServerConfig
,
cc
constant
.
ClientConfig
)
(
naming_client
.
INamingClient
,
error
)
{
if
share
{
clientPoolOnce
.
Do
(
initNacosClientPool
)
clientPool
.
Lock
()
defer
clientPool
.
Unlock
()
if
client
,
ok
:=
clientPool
.
namingClient
[
name
];
ok
{
return
client
,
nil
}
if
!
share
{
return
newNamingClient
(
sc
,
cc
)
}
clientPoolOnce
.
Do
(
initNacosClientPool
)
clientPool
.
Lock
()
defer
clientPool
.
Unlock
()
if
client
,
ok
:=
clientPool
.
namingClient
[
name
];
ok
{
return
client
,
nil
}
cfg
:=
vo
.
NacosClientParam
{
ClientConfig
:
&
cc
,
ServerConfigs
:
sc
}
client
,
err
:=
clients
.
NewNamingClient
(
cfg
)
client
,
err
:=
newNamingClient
(
sc
,
cc
)
if
err
!=
nil
{
return
nil
,
err
}
if
share
{
clientPool
.
namingClient
[
name
]
=
client
}
clientPool
.
namingClient
[
name
]
=
client
return
client
,
err
}
// NewNacosConfigClient create config client
func
NewNacosConfigClient
(
name
string
,
share
bool
,
sc
[]
constant
.
ServerConfig
,
cc
constant
.
ClientConfig
)
(
config_client
.
IConfigClient
,
error
)
{
if
share
{
configClientPoolOnce
.
Do
(
initNacosConfigClientPool
)
configClientPool
.
Lock
()
defer
configClientPool
.
Unlock
()
if
client
,
ok
:=
configClientPool
.
configClient
[
name
];
ok
{
return
client
,
nil
}
if
!
share
{
return
newConfigClient
(
sc
,
cc
)
}
cfg
:=
vo
.
NacosClientParam
{
ClientConfig
:
&
cc
,
ServerConfigs
:
sc
}
client
,
err
:=
clients
.
NewConfigClient
(
cfg
)
configClientPoolOnce
.
Do
(
initNacosConfigClientPool
)
configClientPool
.
Lock
()
defer
configClientPool
.
Unlock
()
if
client
,
ok
:=
configClientPool
.
configClient
[
name
];
ok
{
return
client
,
nil
}
client
,
err
:=
newConfigClient
(
sc
,
cc
)
if
err
!=
nil
{
return
nil
,
err
}
if
share
{
configClientPool
.
configClient
[
name
]
=
client
}
configClientPool
.
configClient
[
name
]
=
client
return
client
,
err
}
func
newNamingClient
(
sc
[]
constant
.
ServerConfig
,
cc
constant
.
ClientConfig
)
(
naming_client
.
INamingClient
,
error
)
{
cfg
:=
vo
.
NacosClientParam
{
ClientConfig
:
&
cc
,
ServerConfigs
:
sc
}
return
clients
.
NewNamingClient
(
cfg
)
}
func
newConfigClient
(
sc
[]
constant
.
ServerConfig
,
cc
constant
.
ClientConfig
)
(
config_client
.
IConfigClient
,
error
)
{
cfg
:=
vo
.
NacosClientParam
{
ClientConfig
:
&
cc
,
ServerConfigs
:
sc
}
return
clients
.
NewConfigClient
(
cfg
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment