1
1
package autoloader
2
2
3
3
import (
4
+ "github.com/caarlos0/env/v6"
4
5
"github.com/fsnotify/fsnotify"
5
6
"github.com/kyaxcorp/go-core/core/config"
6
7
cfgData "github.com/kyaxcorp/go-core/core/config/data"
@@ -215,18 +216,25 @@ func StartAutoLoader(c Config) error {
215
216
216
217
//log.Println(c.Get("main"))
217
218
219
+ // ==================== DEFAULTS ====================\\
220
+ // This is the Standard Config Structure
218
221
obj := & model.Model {}
219
222
if _err := defaults .Set (obj ); _err != nil {
220
223
panic (_err )
221
224
}
222
225
// I'm not sure if i am doing right over here!... but it works... (13.05.2021)
223
226
cfgData .MainConfig = * obj
224
227
228
+ // This is the Custom Config Structure
225
229
objCustom := c .CustomConfigModel
226
230
if _err := defaults .Set (objCustom ); _err != nil {
227
231
panic (_err )
228
232
}
233
+ // ==================== DEFAULTS ====================\\
229
234
235
+ //
236
+
237
+ // =================== VIPER SET ======================\\
230
238
// c.Sub("main")
231
239
_err = cfgData .MainConfigViper .UnmarshalKey ("main" , & cfgData .MainConfig )
232
240
if _err != nil {
@@ -237,6 +245,21 @@ func StartAutoLoader(c Config) error {
237
245
if _err != nil {
238
246
return err .New (0 , "failed to decode 'custom' key from config -> " + _err .Error ())
239
247
}
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
+ //
240
263
241
264
// We should save the configuration only if has being changed!
242
265
// But this can be made by saving in other temporary location, and after that comparing the contents of the both files!
0 commit comments