本文整理汇总了Golang中github.com/tideland/gocells/cells.Event.Payload方法的典型用法代码示例。如果您正苦于以下问题:Golang Event.Payload方法的具体用法?Golang Event.Payload怎么用?Golang Event.Payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tideland/gocells/cells.Event
的用法示例。
在下文中一共展示了Event.Payload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newEventData
// 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
}
示例2: ProcessEvent
// 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
}
示例3: payloadCents
// 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)
}
示例4: ProcessEvent
// 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
}
示例5: Configuration
// 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
}
示例6: ProcessEvent
func (b *emitBehavior) ProcessEvent(event cells.Event) error {
return b.c.EmitNew(sleepTopic, event.Payload())
}