github.com/dubbogo/gost@v1.14.0/database/kv/etcd/v3/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 gxetcd 19 20 import ( 21 "time" 22 ) 23 24 const ( 25 // ConnDelay connection delay 26 ConnDelay = 3 27 // MaxFailTimes max failure times 28 MaxFailTimes = 15 29 // RegistryETCDV3Client client Name 30 RegistryETCDV3Client = "etcd registry" 31 // MetadataETCDV3Client client Name 32 MetadataETCDV3Client = "etcd metadata" 33 ) 34 35 // Options client configuration 36 type Options struct { 37 // Name etcd server name 38 Name string 39 // Endpoints etcd endpoints 40 Endpoints []string 41 // Client etcd client 42 Client *Client 43 // Timeout timeout 44 Timeout time.Duration 45 // Heartbeat second 46 Heartbeat int 47 } 48 49 // Option will define a function of handling Options 50 type Option func(*Options) 51 52 // WithEndpoints sets etcd client endpoints 53 func WithEndpoints(endpoints ...string) Option { 54 return func(opt *Options) { 55 opt.Endpoints = endpoints 56 } 57 } 58 59 // WithName sets etcd client name 60 func WithName(name string) Option { 61 return func(opt *Options) { 62 opt.Name = name 63 } 64 } 65 66 // WithTimeout sets etcd client timeout 67 func WithTimeout(timeout time.Duration) Option { 68 return func(opt *Options) { 69 opt.Timeout = timeout 70 } 71 } 72 73 // WithHeartbeat sets etcd client heartbeat 74 func WithHeartbeat(heartbeat int) Option { 75 return func(opt *Options) { 76 opt.Heartbeat = heartbeat 77 } 78 }