Commit fde1b715 authored by wangwx's avatar wangwx

fix comment

parent eaa68766
...@@ -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 ...ZkClientOption) (*ZookeeperClient, error) { func NewZookeeperClient(name string, zkAddrs []string, share bool, opts ...zkClientOption) (*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 *Options) { return func(opt *options) {
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{},
} }
options := &Options{} option := &options{}
for _, opt := range opts { for _, opt := range opts {
opt(options) opt(option)
} }
// connect to zookeeper // connect to zookeeper
if options.Ts != nil { if option.Ts != nil {
ts = options.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 {
......
...@@ -27,18 +27,18 @@ import ( ...@@ -27,18 +27,18 @@ import (
) )
// nolint // nolint
type Options struct { type options 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(*Options) type Option func(*options)
// WithZkName sets zk Client name // WithZkName sets zk Client name
func WithZkName(name string) Option { func WithZkName(name string) Option {
return func(opt *Options) { return func(opt *options) {
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 ZkClientOption func(*ZookeeperClient) type zkClientOption func(*ZookeeperClient)
// WithZkEventHandler sets zk Client event // WithZkEventHandler sets zk Client event
func WithZkEventHandler(handler ZkEventHandler) ZkClientOption { func WithZkEventHandler(handler ZkEventHandler) zkClientOption {
return func(opt *ZookeeperClient) { return func(opt *ZookeeperClient) {
opt.zkEventHandler = handler opt.zkEventHandler = handler
} }
} }
// WithZkEventHandler sets zk Client timeout // WithZkTimeOut sets zk Client timeout
func WithZkTimeOut(t time.Duration) ZkClientOption { func WithZkTimeOut(t time.Duration) zkClientOption {
return func(opt *ZookeeperClient) { return func(opt *ZookeeperClient) {
opt.Timeout = t opt.Timeout = t
} }
......
Markdown is supported
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