summaryrefslogtreecommitdiff
path: root/configfiles.go
diff options
context:
space:
mode:
Diffstat (limited to 'configfiles.go')
-rw-r--r--configfiles.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/configfiles.go b/configfiles.go
index f758058..65df0c3 100644
--- a/configfiles.go
+++ b/configfiles.go
@@ -1,14 +1,45 @@
package main
import (
+ "fmt"
"os"
"path/filepath"
"strings"
"time"
+ pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log"
)
+var cluster *pb.Cluster
+
+func readConfigFile() {
+ homeDir, _ := os.UserHomeDir()
+ fullname := filepath.Join(homeDir, ".config/virtigo.json")
+ pfile, err := os.ReadFile(fullname)
+ if err != nil {
+ log.Info("open config file :", err)
+ return
+ }
+ err = cluster.UnmarshalJSON(pfile)
+ if err != nil {
+ log.Info("create json failed", err)
+ return
+ }
+}
+
+func writeConfigFile() {
+ homeDir, _ := os.UserHomeDir()
+ fullname := filepath.Join(homeDir, ".config/virtigo.json")
+ cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
+ if err != nil {
+ log.Info("open config file :", err)
+ return
+ }
+ json := cluster.FormatJSON()
+ fmt.Fprintln(cfgfile, json)
+}
+
func readDropletFile(filename string) {
// fmt.Fprintln(w, "GOT TEST?")
homeDir, _ := os.UserHomeDir()