|
| 1 | +package cfg |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "github.com/spf13/pflag" |
| 7 | + "github.com/spf13/viper" |
| 8 | +) |
| 9 | + |
| 10 | +//go:generate mockgen -destination ../mocks/mock-global-viper-config.go -package mocks -source global-config.go -mock_names ViperConfig=MockViperConfig |
| 11 | + |
| 12 | +type ViperConfig interface { |
| 13 | + AddConfigPath(in string) |
| 14 | + AutomaticEnv() |
| 15 | + BindFlagValue(key string, flag viper.FlagValue) error |
| 16 | + BindFlagValues(flags viper.FlagValueSet) error |
| 17 | + BindPFlag(key string, flag *pflag.Flag) error |
| 18 | + ConfigFileUsed() string |
| 19 | + Get(key string) interface{} |
| 20 | + GetBool(key string) bool |
| 21 | + GetDuration(key string) time.Duration |
| 22 | + GetFloat64(key string) float64 |
| 23 | + GetInt(key string) int |
| 24 | + GetInt32(key string) int32 |
| 25 | + GetInt64(key string) int64 |
| 26 | + GetIntSlice(key string) []int |
| 27 | + GetUint(key string) uint |
| 28 | + GetUint16(key string) uint16 |
| 29 | + GetUint32(key string) uint32 |
| 30 | + GetUint64(key string) uint64 |
| 31 | + GetTime(key string) time.Time |
| 32 | + GetSizeInBytes(key string) uint |
| 33 | + GetString(key string) string |
| 34 | + GetStringMap(key string) map[string]interface{} |
| 35 | + GetStringMapString(key string) map[string]string |
| 36 | + GetStringMapStringSlice(key string) map[string][]string |
| 37 | + GetStringSlice(key string) []string |
| 38 | + InConfig(key string) bool |
| 39 | + ReadInConfig() error |
| 40 | + SetConfigFile(in string) |
| 41 | + SetConfigName(in string) |
| 42 | + SetConfigType(in string) |
| 43 | + SetTypeByDefaultValue(enable bool) |
| 44 | + Sub(key string) *viper.Viper |
| 45 | + Unmarshal(rawVal interface{}, opts ...viper.DecoderConfigOption) error |
| 46 | + UnmarshalExact(rawVal interface{}, opts ...viper.DecoderConfigOption) error |
| 47 | + UnmarshalKey(key string, rawVal interface{}, opts ...viper.DecoderConfigOption) error |
| 48 | +} |
| 49 | + |
| 50 | +type GlobalViperConfig struct { |
| 51 | +} |
| 52 | + |
| 53 | +func (p *GlobalViperConfig) AddConfigPath(in string) { |
| 54 | + viper.AddConfigPath(in) |
| 55 | +} |
| 56 | + |
| 57 | +func (p *GlobalViperConfig) AutomaticEnv() { |
| 58 | + viper.AutomaticEnv() |
| 59 | +} |
| 60 | + |
| 61 | +func (p *GlobalViperConfig) BindFlagValue(key string, flag viper.FlagValue) error { |
| 62 | + return viper.BindFlagValue(key, flag) |
| 63 | +} |
| 64 | + |
| 65 | +func (p *GlobalViperConfig) BindFlagValues(flags viper.FlagValueSet) error { |
| 66 | + return viper.BindFlagValues(flags) |
| 67 | +} |
| 68 | + |
| 69 | +func (p *GlobalViperConfig) BindPFlag(key string, flag *pflag.Flag) error { |
| 70 | + return viper.BindPFlag(key, flag) |
| 71 | +} |
| 72 | + |
| 73 | +func (p *GlobalViperConfig) ConfigFileUsed() string { |
| 74 | + return viper.ConfigFileUsed() |
| 75 | +} |
| 76 | + |
| 77 | +func (p *GlobalViperConfig) Get(key string) interface{} { |
| 78 | + return viper.Get(key) |
| 79 | +} |
| 80 | + |
| 81 | +func (p *GlobalViperConfig) GetBool(key string) bool { |
| 82 | + return viper.GetBool(key) |
| 83 | +} |
| 84 | + |
| 85 | +func (p *GlobalViperConfig) GetDuration(key string) time.Duration { |
| 86 | + return viper.GetDuration(key) |
| 87 | +} |
| 88 | + |
| 89 | +func (p *GlobalViperConfig) GetFloat64(key string) float64 { |
| 90 | + return viper.GetFloat64(key) |
| 91 | +} |
| 92 | + |
| 93 | +func (p *GlobalViperConfig) GetInt(key string) int { |
| 94 | + return viper.GetInt(key) |
| 95 | +} |
| 96 | + |
| 97 | +func (p *GlobalViperConfig) GetInt32(key string) int32 { |
| 98 | + return viper.GetInt32(key) |
| 99 | +} |
| 100 | + |
| 101 | +func (p *GlobalViperConfig) GetInt64(key string) int64 { |
| 102 | + return viper.GetInt64(key) |
| 103 | +} |
| 104 | + |
| 105 | +func (p *GlobalViperConfig) GetIntSlice(key string) []int { |
| 106 | + return viper.GetIntSlice(key) |
| 107 | +} |
| 108 | + |
| 109 | +func (p *GlobalViperConfig) GetUint(key string) uint { |
| 110 | + return viper.GetUint(key) |
| 111 | +} |
| 112 | + |
| 113 | +func (p *GlobalViperConfig) GetUint16(key string) uint16 { |
| 114 | + return viper.GetUint16(key) |
| 115 | +} |
| 116 | + |
| 117 | +func (p *GlobalViperConfig) GetUint32(key string) uint32 { |
| 118 | + return viper.GetUint32(key) |
| 119 | +} |
| 120 | + |
| 121 | +func (p *GlobalViperConfig) GetUint64(key string) uint64 { |
| 122 | + return viper.GetUint64(key) |
| 123 | +} |
| 124 | + |
| 125 | +func (p *GlobalViperConfig) GetTime(key string) time.Time { |
| 126 | + return viper.GetTime(key) |
| 127 | +} |
| 128 | + |
| 129 | +func (p *GlobalViperConfig) GetSizeInBytes(key string) uint { |
| 130 | + return viper.GetSizeInBytes(key) |
| 131 | +} |
| 132 | + |
| 133 | +func (p *GlobalViperConfig) GetString(key string) string { |
| 134 | + return viper.GetString(key) |
| 135 | +} |
| 136 | + |
| 137 | +func (p *GlobalViperConfig) GetStringMap(key string) map[string]interface{} { |
| 138 | + return viper.GetStringMap(key) |
| 139 | +} |
| 140 | + |
| 141 | +func (p *GlobalViperConfig) GetStringMapString(key string) map[string]string { |
| 142 | + return viper.GetStringMapString(key) |
| 143 | +} |
| 144 | + |
| 145 | +func (p *GlobalViperConfig) GetStringMapStringSlice(key string) map[string][]string { |
| 146 | + return viper.GetStringMapStringSlice(key) |
| 147 | +} |
| 148 | + |
| 149 | +func (p *GlobalViperConfig) GetStringSlice(key string) []string { |
| 150 | + return viper.GetStringSlice(key) |
| 151 | +} |
| 152 | + |
| 153 | +func (p *GlobalViperConfig) InConfig(key string) bool { |
| 154 | + return viper.InConfig(key) |
| 155 | +} |
| 156 | + |
| 157 | +func (p *GlobalViperConfig) ReadInConfig() error { |
| 158 | + return viper.ReadInConfig() |
| 159 | +} |
| 160 | + |
| 161 | +func (p *GlobalViperConfig) SetConfigFile(in string) { |
| 162 | + viper.SetConfigFile(in) |
| 163 | +} |
| 164 | + |
| 165 | +func (p *GlobalViperConfig) SetConfigName(in string) { |
| 166 | + viper.SetConfigName(in) |
| 167 | +} |
| 168 | + |
| 169 | +func (p *GlobalViperConfig) SetConfigType(in string) { |
| 170 | + viper.SetConfigType(in) |
| 171 | +} |
| 172 | + |
| 173 | +func (p *GlobalViperConfig) SetTypeByDefaultValue(enable bool) { |
| 174 | + viper.SetTypeByDefaultValue(enable) |
| 175 | +} |
| 176 | + |
| 177 | +func (p *GlobalViperConfig) Sub(key string) *viper.Viper { |
| 178 | + return viper.Sub(key) |
| 179 | +} |
| 180 | + |
| 181 | +func (p *GlobalViperConfig) Unmarshal(rawVal interface{}, opts ...viper.DecoderConfigOption) error { |
| 182 | + return viper.Unmarshal(rawVal, opts...) |
| 183 | +} |
| 184 | + |
| 185 | +func (p *GlobalViperConfig) UnmarshalExact(rawVal interface{}, opts ...viper.DecoderConfigOption) error { |
| 186 | + return viper.UnmarshalExact(rawVal, opts...) |
| 187 | +} |
| 188 | + |
| 189 | +func (p *GlobalViperConfig) UnmarshalKey(key string, rawVal interface{}, opts ...viper.DecoderConfigOption) error { |
| 190 | + return viper.UnmarshalKey(key, rawVal, opts...) |
| 191 | +} |
0 commit comments