github.com/dubbogo/gost@v1.14.0/database/kv/zk/options.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package gxzookeeper
    19  
    20  import (
    21  	"time"
    22  )
    23  
    24  import (
    25  	"github.com/dubbogo/go-zookeeper/zk"
    26  )
    27  
    28  // nolint
    29  type options struct {
    30  	ZkName string
    31  	Client *ZookeeperClient
    32  	Ts     *zk.TestCluster
    33  }
    34  
    35  // Option will define a function of handling Options
    36  type Option func(*options)
    37  
    38  // WithZkName sets zk Client name
    39  func WithZkName(name string) Option {
    40  	return func(opt *options) {
    41  		opt.ZkName = name
    42  	}
    43  }
    44  
    45  type zkClientOption func(*ZookeeperClient)
    46  
    47  // WithZkEventHandler sets zk Client event
    48  func WithZkEventHandler(handler ZkEventHandler) zkClientOption {
    49  	return func(opt *ZookeeperClient) {
    50  		opt.zkEventHandler = handler
    51  	}
    52  }
    53  
    54  // WithZkTimeOut sets zk Client timeout
    55  func WithZkTimeOut(t time.Duration) zkClientOption {
    56  	return func(opt *ZookeeperClient) {
    57  		opt.Timeout = t
    58  	}
    59  }