aicra/internal/config/public.go

35 lines
668 B
Go
Raw Normal View History

2018-05-20 08:46:39 +00:00
package config
2018-05-19 13:17:21 +00:00
import (
"encoding/json"
"os"
)
2018-05-20 08:46:39 +00:00
// Load builds a structured representation of the
2018-05-19 13:17:21 +00:00
// configuration file located at @path
// The struct definition checks for most format errors
2018-05-20 08:46:39 +00:00
func Load(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-20 08:46:39 +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
2018-05-20 08:46:39 +00:00
2018-05-19 13:17:21 +00:00
}