From e24ee326856f3a8351e4c3bc8e361a073c0cda5e Mon Sep 17 00:00:00 2001 From: Snoosaphone Date: Sat, 28 Dec 2019 00:44:14 -0600 Subject: [PATCH] Adding the Config loader library --- main.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..f82cde1 --- /dev/null +++ b/main.go @@ -0,0 +1,23 @@ +package config + +import ( + "encoding/json" + "os" +) + +// Requires a struct to be passed via address eg. Load(&interfaceName), and the name/location of the config file. +func Load(s interface{}, configFile string) { + filePtr, err := os.Open(configFile) + defer filePtr.Close() + + if err != nil { + panic(err) + } + + decoder := json.NewDecoder(filePtr) + err = decoder.Decode(&s) + + if err != nil { + panic(err) + } +} \ No newline at end of file