1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 16:49:42 +00:00
tempgopher/config.go
2018-10-02 13:10:41 -06:00

40 lines
1.1 KiB
Go

package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
// Sensor defines configuration for a temperature sensor.
type Sensor struct {
ID string `json:"id" yaml:"id"`
Alias string `json:"alias" yaml:"alias"`
HighTemp float64 `json:"hightemp" yaml:"hightemp"`
LowTemp float64 `json:"lowtemp" yaml:"lowtemp"`
HeatGPIO int32 `json:"heatgpio" yaml:"heatgpio"`
HeatInvert bool `json:"heatinvert" yaml:"heatinvert"`
HeatMinutes float64 `json:"heatminutes" yaml:"heatminutes"`
CoolGPIO int32 `json:"coolgpio" yaml:"coolgpio"`
CoolInvert bool `json:"coolinvert" yaml:"coolinvert"`
CoolMinutes float64 `json:"coolminutes" yaml:"coolminutes"`
Verbose bool `json:"verbose" yaml:"verbose"`
}
// Config contains the applications configuration
type Config struct {
Sensors []Sensor `yaml:"sensors"`
}
// LoadConfig will loads a file and parses it into a Config struct
func LoadConfig(path string) (*Config, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
var config Config
yaml.Unmarshal(data, &config)
return &config, nil
}