aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2018-05-24 23:19:26 -0400
committerBen Burwell <ben@benburwell.com>2018-05-24 23:19:26 -0400
commit65b8fb514db9fc5125494b3393699bf666ed9cb2 (patch)
tree1403327124796b215ebdb1982af135943732e6cd /config.go
parenta3786c8698f8b7c85d09e241cf09dc0e8ced9da2 (diff)
Get lat/long from config file
Diffstat (limited to 'config.go')
-rw-r--r--config.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..a12a240
--- /dev/null
+++ b/config.go
@@ -0,0 +1,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
+ }
+}