From 853993cdd6f874896d2982401a695cb82e2e6ecc Mon Sep 17 00:00:00 2001 From: nytpu Date: Thu, 18 Mar 2021 11:08:23 -0600 Subject: [PATCH] add method to write structs to disk --- core/core.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/core.go b/core/core.go index 70f9cb7..1f92d76 100644 --- a/core/core.go +++ b/core/core.go @@ -62,3 +62,18 @@ func Init(dataPath string) error { } return nil } + +func (d *FullData) WriteJSON(dataPath string) error { + d.Lock() + jsonBytes, err := json.MarshalIndent(&d, "", "\t") + d.Unlock() + if err != nil { + return err + } + err = ioutil.WriteFile(filepath.Join(dataPath, "comitium.json"), jsonBytes, 0666) + if err != nil { + return err + } + + return nil +}