本文整理汇总了Golang中github.com/barnybug/gohome/pubsub.Event.Bytes方法的典型用法代码示例。如果您正苦于以下问题:Golang Event.Bytes方法的具体用法?Golang Event.Bytes怎么用?Golang Event.Bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/barnybug/gohome/pubsub.Event
的用法示例。
在下文中一共展示了Event.Bytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeToLogFile
func writeToLogFile(ev *pubsub.Event) {
name := ev.Topic
device := services.Config.LookupDeviceName(ev)
if device != "" {
ev.Fields["device"] = device
}
p := path.Join(logDir, name)
ensureDirectory(p)
p = path.Join(p, "data.log")
// reopen the log file each time, so that log rotation can happen in the
// background.
// TODO: could this be done more smartly by checking inode and only
// reopening when it changes?
fio, err := os.OpenFile(p, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
defer fio.Close()
if err != nil {
log.Println("Couldn't write file:", err)
return
}
fio.Write(ev.Bytes())
fio.WriteString("\n")
}
示例2: Emit
// Emit an event
func (pub *Publisher) Emit(ev *pubsub.Event) {
// put all topics under gohome/
topic := "gohome/" + ev.Topic
r := pub.client.Publish(MQTT.QOS_ONE, topic, ev.Bytes())
<-r
}