Skip to content

Commit 994613f

Browse files
authored
Merge pull request #18 from DrOctavius/main
Added config env reader
2 parents 7ebcacc + 7b7916f commit 994613f

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Diff for: core/config/autoloader/load.go

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package autoloader
22

33
import (
4+
"github.com/caarlos0/env/v6"
45
"github.com/fsnotify/fsnotify"
56
"github.com/kyaxcorp/go-core/core/config"
67
cfgData "github.com/kyaxcorp/go-core/core/config/data"
@@ -215,18 +216,25 @@ func StartAutoLoader(c Config) error {
215216

216217
//log.Println(c.Get("main"))
217218

219+
// ==================== DEFAULTS ====================\\
220+
// This is the Standard Config Structure
218221
obj := &model.Model{}
219222
if _err := defaults.Set(obj); _err != nil {
220223
panic(_err)
221224
}
222225
// I'm not sure if i am doing right over here!... but it works... (13.05.2021)
223226
cfgData.MainConfig = *obj
224227

228+
// This is the Custom Config Structure
225229
objCustom := c.CustomConfigModel
226230
if _err := defaults.Set(objCustom); _err != nil {
227231
panic(_err)
228232
}
233+
// ==================== DEFAULTS ====================\\
229234

235+
//
236+
237+
// =================== VIPER SET ======================\\
230238
// c.Sub("main")
231239
_err = cfgData.MainConfigViper.UnmarshalKey("main", &cfgData.MainConfig)
232240
if _err != nil {
@@ -237,6 +245,21 @@ func StartAutoLoader(c Config) error {
237245
if _err != nil {
238246
return err.New(0, "failed to decode 'custom' key from config -> "+_err.Error())
239247
}
248+
// =================== VIPER SET ======================\\
249+
250+
//
251+
252+
// ===================== ENV ========================\\
253+
if _err = env.Parse(&cfgData.MainConfig); _err != nil {
254+
return err.New(0, "failed to set env variables for MainConfig -> "+_err.Error())
255+
}
256+
257+
if _err = env.Parse(c.CustomConfig); _err != nil {
258+
return err.New(0, "failed to set env variables for CustomConfig -> "+_err.Error())
259+
}
260+
// ===================== ENV ========================\\
261+
262+
//
240263

241264
// We should save the configuration only if has being changed!
242265
// But this can be made by saving in other temporary location, and after that comparing the contents of the both files!

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040
)
4141

4242
require (
43+
github.com/caarlos0/env/v6 v6.10.0 // indirect
4344
github.com/gin-contrib/sse v0.1.0 // indirect
4445
github.com/go-ole/go-ole v1.2.6 // indirect
4546
github.com/go-playground/locales v0.14.0 // indirect

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
8383
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
8484
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
8585
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
86+
github.com/caarlos0/env/v6 v6.10.0 h1:lA7sxiGArZ2KkiqpOQNf8ERBRWI+v8MWIH+eGjSN22I=
87+
github.com/caarlos0/env/v6 v6.10.0/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc=
8688
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
8789
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
8890
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=

0 commit comments

Comments
 (0)