本文整理匯總了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
}