summaryrefslogtreecommitdiff
path: root/configfiles.go
diff options
context:
space:
mode:
Diffstat (limited to 'configfiles.go')
-rw-r--r--configfiles.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/configfiles.go b/configfiles.go
new file mode 100644
index 0000000..b7999c5
--- /dev/null
+++ b/configfiles.go
@@ -0,0 +1,46 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+func readConfigFile(filename string) {
+ // fmt.Fprintln(w, "GOT TEST?")
+ homeDir, _ := os.UserHomeDir()
+ fullname := filepath.Join(homeDir, ".config/virtigo/", filename)
+ pfile, err := os.ReadFile(fullname)
+ if err != nil {
+ log.Info("No config file :", err)
+ // w.Write(pfile)
+ return
+ }
+
+ f := string(pfile)
+ for _, line := range strings.Split(f, "\n") {
+ fields := strings.Fields(line)
+ if len(fields) < 1 {
+ continue
+ }
+ name := fields[0]
+ d := findDroplet(name)
+ if d == nil {
+ // this is a new unknown droplet (not in the config file)
+ d = new(DropletT)
+ d.Hostname = name
+ if len(fields) < 2 || fields[1] != "ON" {
+ d.State = "OFF"
+ } else {
+ d.State = "ON"
+ }
+ me.droplets = append(me.droplets, d)
+ log.Log(EVENT, "NEW CONFIG DROPLET", d.Hostname, d.State)
+ } else {
+ log.Info("not sure what to do here. duplicate", name, "in config file")
+ }
+
+ }
+}