-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
47 lines (38 loc) · 779 Bytes
/
Copy pathconfig.go
File metadata and controls
47 lines (38 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
var (
config *Config
)
type Config struct {
HomeKit HomeKitConfig
Doors []DoorConfig
}
type DoorConfig struct {
Name string
Manufacturer string
Model string
TopGPIO int `yaml:"top_gpio"`
BottomGPIO int `yaml:"bottom_gpio"`
RelayGPIO int `yaml:"relay_gpio"`
}
type HomeKitConfig struct {
PIN string
StoragePath string `yaml:"storage_path"`
}
// loadConfiguration reads YAML data from the specified file name and populates
// a Config object.
func loadConfig(file string) (*Config, error) {
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
c := new(Config)
err = yaml.Unmarshal(data, c)
if err != nil {
return nil, err
}
return c, err
}