From d4fd1f4112156ebef97c02a60d90a3127996e756 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Mon, 18 Oct 2021 22:36:54 +0200 Subject: [PATCH] Config init a bit better --- config/config.go | 21 ++++++++++++++++++++- db/db.go | 10 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 db/db.go diff --git a/config/config.go b/config/config.go index f946e3c..2f1e934 100644 --- a/config/config.go +++ b/config/config.go @@ -8,6 +8,11 @@ import ( "github.com/spf13/viper" ) +var ( + config *Configuration + vconfig *viper.Viper +) + type Configuration struct { Settings Settings `mapstructure:"settings"` Devices Devices `mapstructure:"devices"` @@ -44,11 +49,25 @@ func Load() *Configuration { var cfg *Configuration + //Unmarshal all into Configuration type err := vconfig.Unmarshal(cfg) if err != nil { fmt.Printf("Error occured when loading config: %v\n", err) panic("No configuration available!") } - //Unmarshal all into Configuration type + for k, v := range cfg.Backups { + v.Name = k + } + for k, v := range cfg.Devices { + v.Name = k + } return cfg } + +func Init() { + config = Load() +} + +func Get() *Configuration { + return config +} diff --git a/db/db.go b/db/db.go new file mode 100644 index 0000000..0cd6270 --- /dev/null +++ b/db/db.go @@ -0,0 +1,10 @@ +package db + +import "encoding/json" + +var database map[string]string + +func Save() { + jsonstr := json.Marshal(database) + +}