github.com/uber/kraken@v0.1.4/tracker/peerstore/config.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package peerstore 15 16 import ( 17 "time" 18 ) 19 20 // Config defines Store configuration. 21 type Config struct { 22 Redis RedisConfig `yaml:"redis"` 23 } 24 25 // RedisConfig defines RedisStore configuration. 26 // TODO(evelynl94): rename 27 type RedisConfig struct { 28 Addr string `yaml:"addr"` 29 DialTimeout time.Duration `yaml:"dial_timeout"` 30 ReadTimeout time.Duration `yaml:"read_timeout"` 31 WriteTimeout time.Duration `yaml:"write_timeout"` 32 PeerSetWindowSize time.Duration `yaml:"peer_set_window_size"` 33 MaxPeerSetWindows int `yaml:"max_peer_set_windows"` 34 MaxIdleConns int `yaml:"max_idle_conns"` 35 MaxActiveConns int `yaml:"max_active_conns"` 36 IdleConnTimeout time.Duration `yaml:"idle_conn_timeout"` 37 } 38 39 func (c *RedisConfig) applyDefaults() { 40 if c.DialTimeout == 0 { 41 c.DialTimeout = 5 * time.Second 42 } 43 if c.ReadTimeout == 0 { 44 c.ReadTimeout = 30 * time.Second 45 } 46 if c.WriteTimeout == 0 { 47 c.WriteTimeout = 30 * time.Second 48 } 49 if c.PeerSetWindowSize == 0 { 50 c.PeerSetWindowSize = time.Hour 51 } 52 if c.MaxPeerSetWindows == 0 { 53 c.MaxPeerSetWindows = 5 54 } 55 if c.MaxIdleConns == 0 { 56 c.MaxIdleConns = 10 57 } 58 if c.MaxActiveConns == 0 { 59 c.MaxActiveConns = 500 60 } 61 if c.IdleConnTimeout == 0 { 62 c.IdleConnTimeout = 60 * time.Second 63 } 64 }