write out json cfg file

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-22 15:16:37 -05:00
parent 70a506bc59
commit 91d2a8a19d
1 changed files with 31 additions and 0 deletions

View File

@ -1,14 +1,45 @@
package main package main
import ( import (
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log" "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) { func readDropletFile(filename string) {
// fmt.Fprintln(w, "GOT TEST?") // fmt.Fprintln(w, "GOT TEST?")
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()