-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
114 lines (97 loc) · 2.69 KB
/
config.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"strings"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func getMetadataConfig() MetadataS3Config {
parseConfig()
S3Conf := configS3Storage()
return S3Conf
}
func getDeploymentConfig() DeployS3Config {
parseConfig()
dS3Conf := deployS3Storage()
return dS3Conf
}
type MetadataS3Config struct {
URL string
Port int
AccessKey string
SecretKey string
Bucket string
Region string
Chunksize int
Cacert string
WebMetadataFolder string
}
type DeployS3Config struct {
URL string
Port int
AccessKey string
SecretKey string
Bucket string
Region string
Chunksize int
Cacert string
}
func configS3Storage() MetadataS3Config {
s3 := MetadataS3Config{}
s3.URL = viper.GetString("S3MetadataBucket.url")
s3.AccessKey = viper.GetString("S3MetadataBucket.accesskey")
s3.SecretKey = viper.GetString("S3MetadataBucket.secretkey")
s3.Bucket = viper.GetString("S3MetadataBucket.bucket")
s3.Port = 9000
s3.WebMetadataFolder = viper.GetString("S3MetadataBucket.WebMetadataFolder")
if viper.IsSet("s3.port") {
s3.Port = viper.GetInt("S3MetadataBucket.port")
}
if viper.IsSet("s3.region") {
s3.Region = viper.GetString("S3MetadataBucket.region")
}
if viper.IsSet("s3.chunksize") {
s3.Chunksize = viper.GetInt("S3MetadataBucket.chunksize") * 1024 * 1024
}
if viper.IsSet("s3.cacert") {
s3.Cacert = viper.GetString("S3MetadataBucket.cacert")
}
return s3
}
func deployS3Storage() DeployS3Config {
s3 := DeployS3Config{}
s3.URL = viper.GetString("S3DeploymentBucket.url")
s3.AccessKey = viper.GetString("S3DeploymentBucket.accesskey")
s3.SecretKey = viper.GetString("S3DeploymentBucket.secretkey")
s3.Bucket = viper.GetString("S3DeploymentBucket.bucket")
s3.Port = 9000
if viper.IsSet("s3.port") {
s3.Port = viper.GetInt("S3DeploymentBucket.port")
}
if viper.IsSet("s3.region") {
s3.Region = viper.GetString("S3DeploymentBucket.region")
}
if viper.IsSet("s3.chunksize") {
s3.Chunksize = viper.GetInt("S3DeploymentBucket.chunksize") * 1024 * 1024
}
if viper.IsSet("s3.cacert") {
s3.Cacert = viper.GetString("S3DeploymentBucket.cacert")
}
return s3
}
func parseConfig() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetConfigType("yaml")
if viper.IsSet("configFile") {
viper.SetConfigFile(viper.GetString("configFile"))
}
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
log.Infoln("No config file found, using ENVs only")
} else {
log.Fatalf("Error when reading config file: '%s'", err)
}
}
}