33 lines
594 B
Go
33 lines
594 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
type AccessPoint struct {
|
|
Name string
|
|
Address string
|
|
}
|
|
|
|
type Config struct {
|
|
AccessPoints []AccessPoint
|
|
}
|
|
|
|
func LoadConfig(path string) (Config, error) {
|
|
var result Config
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return result, errors.New("Could not open config file" + err.Error())
|
|
}
|
|
defer file.Close()
|
|
decoder := json.NewDecoder(file)
|
|
err = decoder.Decode(&result)
|
|
if err != nil {
|
|
return result, errors.New("Could not decode config file" + err.Error())
|
|
}
|
|
|
|
return result, nil
|
|
}
|