github.com/blend/go-sdk@v1.20220411.3/redis/config.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package redis 9 10 import ( 11 "context" 12 "time" 13 14 "github.com/blend/go-sdk/configutil" 15 ) 16 17 // Config is the config type for the redis client. 18 type Config struct { 19 Network string `yaml:"network"` 20 Addr string `yaml:"addr"` 21 SentinelAddrs []string `yaml:"sentinelAddrs"` 22 SentinelPrimaryName string `yaml:"sentinelPrimaryName"` 23 ClusterAddrs []string `yaml:"clusterAddrs"` 24 AuthUser string `yaml:"authUser"` 25 AuthPassword string `yaml:"authPassword"` 26 DB string `yaml:"db"` 27 ConnectTimeout time.Duration `yaml:"connectTimeout"` 28 Timeout time.Duration `yaml:"timeout"` 29 UseTLS bool `yaml:"useTLS"` 30 } 31 32 // Resolve resolves the config. 33 func (c *Config) Resolve(ctx context.Context) error { 34 return configutil.Resolve(ctx, 35 configutil.SetString(&c.Network, configutil.Env("REDIS_NETWORK"), configutil.String(c.Network), configutil.String(DefaultNetwork)), 36 configutil.SetString(&c.Addr, configutil.Env("REDIS_ADDR"), configutil.String(c.Addr), configutil.String(DefaultAddr)), 37 configutil.SetString(&c.DB, configutil.Env("REDIS_DB"), configutil.String(c.DB)), 38 configutil.SetString(&c.AuthUser, configutil.Env("REDIS_AUTH_USER"), configutil.String(c.AuthUser)), 39 configutil.SetString(&c.AuthPassword, configutil.Env("REDIS_AUTH_PASS"), configutil.String(c.AuthPassword)), 40 configutil.SetDuration(&c.ConnectTimeout, configutil.Env("REDIS_CONNECT_TIMEOUT"), configutil.Duration(c.ConnectTimeout), configutil.Duration(DefaultConnectTimeout)), 41 configutil.SetDuration(&c.Timeout, configutil.Env("REDIS_TIMEOUT"), configutil.Duration(c.Timeout), configutil.Duration(DefaultTimeout)), 42 configutil.SetString(&c.SentinelPrimaryName, configutil.Env("REDIS_SENTINEL_PRIMARY_NAME"), configutil.String(c.SentinelPrimaryName), configutil.String("default")), 43 ) 44 }