2018-05-19 13:17:21 +00:00
|
|
|
package gfw
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2018-05-19 19:34:11 +00:00
|
|
|
// LoadConfig builds a struct representation of the
|
2018-05-19 13:17:21 +00:00
|
|
|
// configuration file located at @path
|
|
|
|
// The structure checks for most format errors
|
2018-05-19 19:34:11 +00:00
|
|
|
func LoadConfig(path string) (*controller, error) {
|
2018-05-19 13:17:21 +00:00
|
|
|
|
|
|
|
/* (1) Extract data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Open file */
|
|
|
|
var configFile, err = os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer configFile.Close()
|
|
|
|
|
|
|
|
/* (2) Init receiving dataset */
|
2018-05-19 19:34:11 +00:00
|
|
|
receiver := &controller{}
|
2018-05-19 13:17:21 +00:00
|
|
|
|
|
|
|
/* (3) Decode JSON */
|
|
|
|
decoder := json.NewDecoder(configFile)
|
|
|
|
err = decoder.Decode(receiver)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return receiver, nil
|
|
|
|
}
|