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 diff --git a/droplet.proto b/droplet.proto index 87af716..e34a65e 100644 --- a/droplet.proto +++ b/droplet.proto @@ -29,7 +29,7 @@ message Droplet { string image_url = 15; // url to the image // is it possible to have custom formatting in JSON and TEXT marshal/unmarshal ? - JunkInfo humantest = 16; + // JunkInfo humantest = 16; } enum DropletState {