-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfig.go
109 lines (78 loc) · 2.85 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
package config
import (
"context"
"log/slog"
"os"
"strings"
"github.com/Vilsol/slox"
"github.com/spf13/viper"
"github.com/satisfactorymodding/smr-api/logging"
)
var configDir = "."
func SetConfigDir(newConfigDir string) {
configDir = newConfigDir
}
func InitializeConfig(baseCtx context.Context) context.Context {
if os.Getenv("CI") == "true" {
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "__"))
}
viper.SetConfigName("config")
viper.AddConfigPath(configDir)
viper.AutomaticEnv()
viper.SetEnvPrefix("repo")
initializeDefaults()
err := viper.ReadInConfig() //nolint:ifshort
if err := logging.SetupLogger(nil); err != nil {
panic(err)
}
if baseCtx == nil {
baseCtx = context.Background()
}
if err != nil {
slog.WarnContext(baseCtx, "config initialized using defaults and environment only!", slog.Any("err", err))
}
slox.Info(baseCtx, "Config initialized")
return baseCtx
}
func initializeDefaults() {
viper.SetDefault("host", "0.0.0.0")
viper.SetDefault("port", "5020")
viper.SetDefault("production", true)
viper.SetDefault("profiler", false)
viper.SetDefault("database.redis.host", "localhost")
viper.SetDefault("database.redis.port", 6379)
viper.SetDefault("database.redis.pass", "")
viper.SetDefault("database.redis.db", 1)
viper.SetDefault("database.redis.job_db", 2)
viper.SetDefault("database.postgres.host", "localhost")
viper.SetDefault("database.postgres.port", 5432)
viper.SetDefault("database.postgres.user", "postgres")
viper.SetDefault("database.postgres.pass", "REPLACE_ME")
viper.SetDefault("database.postgres.db", "postgres")
viper.SetDefault("database.postgres.maxconns", 20)
viper.SetDefault("storage.type", "s3")
viper.SetDefault("storage.bucket", "smr")
viper.SetDefault("storage.key", "REPLACE_ME_KEY")
viper.SetDefault("storage.secret", "REPLACE_ME_SECRET")
viper.SetDefault("storage.endpoint", "http://localhost:9000")
viper.SetDefault("storage.region", "eu-central-1")
viper.SetDefault("storage.base_url", "http://localhost:9000")
viper.SetDefault("storage.keypath", "%s/file/%s/%s")
viper.SetDefault("oauth.github.client_id", "")
viper.SetDefault("oauth.github.client_secret", "")
viper.SetDefault("oauth.google.client_id", "")
viper.SetDefault("oauth.google.client_secret", "")
viper.SetDefault("oauth.facebook.client_id", "")
viper.SetDefault("oauth.facebook.client_secret", "")
viper.SetDefault("paseto.public_key", "")
viper.SetDefault("paseto.private_key", "")
viper.SetDefault("discord.webhook_url", "")
viper.SetDefault("discourse.url", "")
viper.SetDefault("discourse.sso_secret", "")
viper.SetDefault("frontend.url", "")
viper.SetDefault("virustotal.key", "")
viper.SetDefault("feature_flags.allow_multi_target_upload", false)
viper.SetDefault("extractor_host", "localhost:50051")
viper.SetDefault("temporal.host", "localhost:7233")
viper.SetDefault("statistics.enabled", true)
}