LoadConfig loads configuration file from path.
(path string, c interface{})
| 37 | |
| 38 | // LoadConfig loads configuration file from path. |
| 39 | func LoadConfig(path string, c interface{}) (err error) { |
| 40 | var jsonFile *os.File |
| 41 | var byteValue []byte |
| 42 | |
| 43 | fmt.Println("Path ", path) |
| 44 | // Open our jsonFile |
| 45 | jsonFile, err = os.Open(path) |
| 46 | // if we os.Open returns an error then handle it |
| 47 | if err != nil { |
| 48 | fmt.Println("LoadConfig error ", err) |
| 49 | return |
| 50 | } |
| 51 | fmt.Println("Successfully Opened json") |
| 52 | // defer the closing of our jsonFile so that we can parse it later on |
| 53 | defer jsonFile.Close() |
| 54 | |
| 55 | // read our opened xmlFile as a byte array. |
| 56 | byteValue, err = ioutil.ReadAll(jsonFile) |
| 57 | if err != nil { |
| 58 | fmt.Println("ReadAll error ", err) |
| 59 | return |
| 60 | } |
| 61 | |
| 62 | err = json.Unmarshal(byteValue, &c) |
| 63 | if err != nil { |
| 64 | fmt.Println("Unmarshal error ", err) |
| 65 | return |
| 66 | } |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | // LoadConfig loads configuration file from path. |
| 71 | func (c *Config) LoadConfig() (err error) { |