diff --git a/config.go b/config.go index 1d7ca3d..4ae6f31 100644 --- a/config.go +++ b/config.go @@ -135,38 +135,33 @@ func (c *Cluster) ConfigLoad() error { c.Hypervisors = append(c.Hypervisors, a) } - if err := c.loadEvents(); err != nil { + var e *Events + e = new(Events) + + if c.E == nil { + c.E = new(Events) + } + if err := e.loadEvents(); err != nil { return err } + // copy them over. is this needed? does the memory free otherwise? + for _, e := range e.Events { + c.E.Events = append(c.E.Events, e) + } return nil } -func (c *Cluster) loadEvents() error { +func (e *Events) loadEvents() error { var data []byte var err error - if c == nil { - fmt.Println("cluster == nil") - os.Exit(-1) - } - - if c.E == nil { - fmt.Println("cluster.E == nil") - c.E = new(Events) - } - - if c.E == nil { - fmt.Println("cluster.E == nil") - os.Exit(-1) - } - // load the events config file if data, err = loadFile("events.json"); err != nil { fmt.Println("broken events.json config file") return err } - err = protojson.Unmarshal(data, c.E) + err = protojson.Unmarshal(data, e) if err != nil { fmt.Println("broken events.json config file") // json load failed. try loading prototext @@ -175,7 +170,7 @@ func (c *Cluster) loadEvents() error { fmt.Println(err) return errors.New("events.text file is broken") } - if err = prototext.Unmarshal(data, c.E); err != nil { + if err = prototext.Unmarshal(data, e); err != nil { fmt.Println("broken events.text config file") fmt.Println(err) return errors.New("events.text file is broken")