blob: a12a2403c5b6562981af71dd574c30c294b54a89 (
plain)
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
|
package main
import (
"io/ioutil"
"log"
"github.com/BurntSushi/xdg"
"gopkg.in/yaml.v2"
)
const XDG_CONFIG_NAME = "phlux"
type PhluxConfig struct {
Latitude float64 `yaml:"latitude"`
Longitude float64 `yaml:"longitude"`
Bridges []struct {
BridgeID string `yaml:"id"`
Token string `yaml:"token"`
} `yaml:"bridges"`
}
func (c *PhluxConfig) Read() {
var paths xdg.Paths
configFile, err := paths.ConfigFile(XDG_CONFIG_NAME)
if err != nil {
log.Printf("No config file found: %s\n", err.Error())
return
}
yamlFile, err := ioutil.ReadFile(configFile)
if err != nil {
log.Printf("Error reading config file %s: %s\n", configFile, err.Error())
return
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Printf("Error unmarshalling yaml: %s\n", err.Error())
return
}
}
|