Adding the Config loader library

This commit is contained in:
Snoosaphone 2019-12-28 00:44:14 -06:00
commit e24ee32685

23
main.go Normal file
View File

@ -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)
}
}