23 lines
446 B
Go
23 lines
446 B
Go
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)
|
|
}
|
|
} |