diff options
| author | Jeff Carr <[email protected]> | 2024-10-22 15:16:37 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-22 15:16:37 -0500 |
| commit | 91d2a8a19de8455fad8c76b57095ea0f7869f1d4 (patch) | |
| tree | 2d4b5a86cd3dc0c9aa2dfbbc123a491a567a674a /configfiles.go | |
| parent | 70a506bc5941df1c4a7b46ec1288011ceb70ddd3 (diff) | |
write out json cfg file
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'configfiles.go')
| -rw-r--r-- | configfiles.go | 31 |
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() |
