From 91d2a8a19de8455fad8c76b57095ea0f7869f1d4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 22 Oct 2024 15:16:37 -0500 Subject: [PATCH] write out json cfg file Signed-off-by: Jeff Carr --- configfiles.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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()