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
fde1b715
Commit
fde1b715
authored
Mar 03, 2021
by
wangwx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix comment
parent
eaa68766
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
13 deletions
+13
-13
client.go
database/kv/zk/client.go
+6
-6
options.go
database/kv/zk/options.go
+7
-7
No files found.
database/kv/zk/client.go
View file @
fde1b715
...
@@ -93,7 +93,7 @@ func initZookeeperClientPool() {
...
@@ -93,7 +93,7 @@ func initZookeeperClientPool() {
}
}
//NewZookeeperClient will create a ZookeeperClient
//NewZookeeperClient will create a ZookeeperClient
func
NewZookeeperClient
(
name
string
,
zkAddrs
[]
string
,
share
bool
,
opts
...
Z
kClientOption
)
(
*
ZookeeperClient
,
error
)
{
func
NewZookeeperClient
(
name
string
,
zkAddrs
[]
string
,
share
bool
,
opts
...
z
kClientOption
)
(
*
ZookeeperClient
,
error
)
{
if
share
{
if
share
{
once
.
Do
(
initZookeeperClientPool
)
once
.
Do
(
initZookeeperClientPool
)
zkClientPool
.
Lock
()
zkClientPool
.
Lock
()
...
@@ -144,7 +144,7 @@ func (z *ZookeeperClient) createZookeeperConn() error {
...
@@ -144,7 +144,7 @@ func (z *ZookeeperClient) createZookeeperConn() error {
// WithTestCluster sets test cluster for zk Client
// WithTestCluster sets test cluster for zk Client
func
WithTestCluster
(
ts
*
zk
.
TestCluster
)
Option
{
func
WithTestCluster
(
ts
*
zk
.
TestCluster
)
Option
{
return
func
(
opt
*
O
ptions
)
{
return
func
(
opt
*
o
ptions
)
{
opt
.
Ts
=
ts
opt
.
Ts
=
ts
}
}
}
}
...
@@ -168,14 +168,14 @@ func NewMockZookeeperClient(name string, timeout time.Duration, opts ...Option)
...
@@ -168,14 +168,14 @@ func NewMockZookeeperClient(name string, timeout time.Duration, opts ...Option)
zkEventHandler
:
&
DefaultHandler
{},
zkEventHandler
:
&
DefaultHandler
{},
}
}
option
s
:=
&
O
ptions
{}
option
:=
&
o
ptions
{}
for
_
,
opt
:=
range
opts
{
for
_
,
opt
:=
range
opts
{
opt
(
option
s
)
opt
(
option
)
}
}
// connect to zookeeper
// connect to zookeeper
if
option
s
.
Ts
!=
nil
{
if
option
.
Ts
!=
nil
{
ts
=
option
s
.
Ts
ts
=
option
.
Ts
}
else
{
}
else
{
ts
,
err
=
zk
.
StartTestCluster
(
1
,
nil
,
nil
,
zk
.
WithRetryTimes
(
40
))
ts
,
err
=
zk
.
StartTestCluster
(
1
,
nil
,
nil
,
zk
.
WithRetryTimes
(
40
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
database/kv/zk/options.go
View file @
fde1b715
...
@@ -27,18 +27,18 @@ import (
...
@@ -27,18 +27,18 @@ import (
)
)
// nolint
// nolint
type
O
ptions
struct
{
type
o
ptions
struct
{
ZkName
string
ZkName
string
Client
*
ZookeeperClient
Client
*
ZookeeperClient
Ts
*
zk
.
TestCluster
Ts
*
zk
.
TestCluster
}
}
// Option will define a function of handling Options
// Option will define a function of handling Options
type
Option
func
(
*
O
ptions
)
type
Option
func
(
*
o
ptions
)
// WithZkName sets zk Client name
// WithZkName sets zk Client name
func
WithZkName
(
name
string
)
Option
{
func
WithZkName
(
name
string
)
Option
{
return
func
(
opt
*
O
ptions
)
{
return
func
(
opt
*
o
ptions
)
{
opt
.
ZkName
=
name
opt
.
ZkName
=
name
}
}
}
}
...
@@ -61,17 +61,17 @@ type ZookeeperClient struct {
...
@@ -61,17 +61,17 @@ type ZookeeperClient struct {
Session
<-
chan
zk
.
Event
Session
<-
chan
zk
.
Event
}
}
type
Z
kClientOption
func
(
*
ZookeeperClient
)
type
z
kClientOption
func
(
*
ZookeeperClient
)
// WithZkEventHandler sets zk Client event
// WithZkEventHandler sets zk Client event
func
WithZkEventHandler
(
handler
ZkEventHandler
)
Z
kClientOption
{
func
WithZkEventHandler
(
handler
ZkEventHandler
)
z
kClientOption
{
return
func
(
opt
*
ZookeeperClient
)
{
return
func
(
opt
*
ZookeeperClient
)
{
opt
.
zkEventHandler
=
handler
opt
.
zkEventHandler
=
handler
}
}
}
}
// WithZk
EventHandler
sets zk Client timeout
// WithZk
TimeOut
sets zk Client timeout
func
WithZkTimeOut
(
t
time
.
Duration
)
Z
kClientOption
{
func
WithZkTimeOut
(
t
time
.
Duration
)
z
kClientOption
{
return
func
(
opt
*
ZookeeperClient
)
{
return
func
(
opt
*
ZookeeperClient
)
{
opt
.
Timeout
=
t
opt
.
Timeout
=
t
}
}
...
...
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