From 62d406e0de0fcfe373ae45ed8920dc8a9e3e1034 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 23 Oct 2024 00:48:35 -0500 Subject: set a homedir Signed-off-by: Jeff Carr --- configfiles.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'configfiles.go') diff --git a/configfiles.go b/configfiles.go index 3146e1b..0eca9a7 100644 --- a/configfiles.go +++ b/configfiles.go @@ -12,8 +12,7 @@ import ( func readConfigFile() { me.cluster = new(pb.Cluster) - homeDir, _ := os.UserHomeDir() - fullname := filepath.Join(homeDir, ".config/virtigo.json") + fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json") pfile, err := os.ReadFile(fullname) if err != nil { log.Info("open config file :", err) @@ -57,8 +56,7 @@ func readConfigFile() { } func writeConfigFile() { - homeDir, _ := os.UserHomeDir() - fullname := filepath.Join(homeDir, ".config/virtigo.json") + fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json") cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666) defer cfgfile.Close() if err != nil { @@ -67,4 +65,19 @@ func writeConfigFile() { } json := me.cluster.FormatJSON() fmt.Fprintln(cfgfile, json) + log.Info("Write:", fullname, "OK") +} + +func writeConfigFileDroplets() { + fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.text") + cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666) + defer cfgfile.Close() + if err != nil { + log.Info("open config file :", err) + return + } + // text := me.cluster.Droplets.FormatTEXT() + text := me.cluster.FormatTEXT() + fmt.Fprintln(cfgfile, text) + log.Info("Write:", fullname, "OK") } -- cgit v1.2.3