// newEventData returns the passed event as event data to collect. func newEventData(event cells.Event) EventData { data := EventData{ Topic: event.Topic(), Payload: event.Payload(), } return data }
// ProcessEvent reads, validates and emits a configuration. func (b *configuratorBehavior) ProcessEvent(event cells.Event) error { switch event.Topic() { case ReadConfigurationTopic: // Read configuration filename, ok := event.Payload().GetString(ConfigurationFilenamePayload) if !ok { logger.Errorf("cannot read configuration without filename payload") return nil } logger.Infof("reading configuration from %q", filename) cfg, err := etc.ReadFile(filename) if err != nil { return errors.Annotate(err, ErrCannotReadConfiguration, errorMessages) } // If wanted then validate it. if b.validate != nil { err = b.validate(cfg) if err != nil { return errors.Annotate(err, ErrCannotValidateConfiguration, errorMessages) } } // All done, emit it. pvs := cells.PayloadValues{ ConfigurationPayload: cfg, } b.cell.EmitNewContext(ConfigurationTopic, pvs, event.Context()) } return nil }
// cents retrieves the cents out of the payload of an event. func payloadCents(event cells.Event) int { cents, ok := event.Payload().Get(cells.DefaultPayload) if !ok { return -1 } return cents.(int) }
// ProcessEvent calls a callback functions with the event data. func (b *callbackBehavior) ProcessEvent(event cells.Event) error { for _, callbackFunc := range b.callbackFuncs { if err := callbackFunc(event.Topic(), event.Payload()); err != nil { return err } } return nil }
// Configuration returns the configuration payload // of the passed event or an empty configuration. func Configuration(event cells.Event) etc.Etc { payload, ok := event.Payload().Get(ConfigurationPayload) if !ok { logger.Warningf("event does not contain configuration payload") cfg, _ := etc.ReadString("{etc}") return cfg } cfg, ok := payload.(etc.Etc) if !ok { logger.Warningf("configuration payload has illegal type") cfg, _ := etc.ReadString("{etc}") return cfg } return cfg }
func (b *emitBehavior) ProcessEvent(event cells.Event) error { return b.c.EmitNew(sleepTopic, event.Payload()) }