-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
49 lines (40 loc) · 1.03 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package config
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/spf13/viper"
"github.com/thomasduchatelle/dphoto/pkg/awssupport/awsfactory"
)
type Config interface {
Get(key string) interface{}
GetString(key string) string
GetStringOrDefault(key string, defaultValue string) string
GetBool(key string) bool
GetInt(key string) int
GetIntOrDefault(key string, defaultValue int) int
GetAWSV2Config() aws.Config
GetAWSFactory() *awsfactory.AWSFactory
}
type viperConfig struct {
*viper.Viper
AWSFactory *awsfactory.AWSFactory
}
func (v *viperConfig) GetAWSV2Config() aws.Config {
return v.AWSFactory.Cfg
}
func (v *viperConfig) GetAWSFactory() *awsfactory.AWSFactory {
return v.AWSFactory
}
func (v *viperConfig) GetStringOrDefault(key string, defaultValue string) string {
value := v.Viper.GetString(key)
if value == "" {
value = defaultValue
}
return value
}
func (v *viperConfig) GetIntOrDefault(key string, defaultValue int) int {
value := v.Viper.GetInt(key)
if value == 0 {
value = defaultValue
}
return value
}