cisgo/pkg/config/config.go

33 lines
594 B
Go
Raw Permalink Normal View History

2022-06-13 20:39:30 +02:00
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
}