summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go39
1 files changed, 26 insertions, 13 deletions
diff --git a/config.go b/config.go
index 192d60d..1a1651c 100644
--- a/config.go
+++ b/config.go
@@ -12,68 +12,81 @@ import (
"google.golang.org/protobuf/encoding/prototext"
)
-func WriteConfig(d *Droplets, h *Hypervisors, e *Events) {
- d.WriteConfigJSON()
- d.WriteConfigTEXT()
+func WriteConfig(d *Droplets, h *Hypervisors, e *Events) bool {
+ if !d.WriteConfigJSON() {
+ return false
+ }
+ if !d.WriteConfigTEXT() {
+ return false
+ }
- e.WriteConfigJSON()
- e.WriteConfigTEXT()
+ if e.WriteConfigJSON() {
+ return false
+ }
+ if e.WriteConfigTEXT() {
+ return false
+ }
+ return true
}
// export as json
-func (e *Events) WriteConfigJSON() {
+func (e *Events) WriteConfigJSON() bool {
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "events.json")
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()
if err != nil {
fmt.Println("open config file :", err)
- return
+ return false
}
text := e.FormatJSON()
fmt.Fprintln(cfgfile, text)
fmt.Println("Write:", fullname, "OK")
+ return true
}
// export as prototext
-func (e *Events) WriteConfigTEXT() {
+func (e *Events) WriteConfigTEXT() bool {
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "events.text")
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()
if err != nil {
fmt.Println("open config file :", err)
- return
+ return false
}
text := e.FormatTEXT()
fmt.Fprintln(cfgfile, text)
fmt.Println("Write:", fullname, "OK")
+ return true
}
// export as json
-func (d *Droplets) WriteConfigJSON() {
+func (d *Droplets) WriteConfigJSON() bool {
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.json")
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()
if err != nil {
fmt.Println("open config file :", err)
- return
+ return false
}
text := d.FormatJSON()
fmt.Fprintln(cfgfile, text)
fmt.Println("Write:", fullname, "OK")
+ return true
}
// export as prototext
-func (d *Droplets) WriteConfigTEXT() {
+func (d *Droplets) WriteConfigTEXT() bool {
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 {
fmt.Println("open config file :", err)
- return
+ return false
}
text := d.FormatTEXT()
fmt.Fprintln(cfgfile, text)
fmt.Println("Write:", fullname, "OK")
+ return true
}
// human readable JSON