本文整理汇总了Golang中github.com/trevex/golem.Connection.Emit方法的典型用法代码示例。如果您正苦于以下问题:Golang Connection.Emit方法的具体用法?Golang Connection.Emit怎么用?Golang Connection.Emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/trevex/golem.Connection
的用法示例。
在下文中一共展示了Connection.Emit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: hello
func hello(conn *golem.Connection, data *Hello) {
fmt.Println("Hello from", data.From, "to", data.To)
conn.Emit("answer", &Answer{"Thanks, client!"})
}
示例2: poke
func poke(conn *golem.Connection) {
fmt.Println("Poke-Event triggered!")
conn.Emit("answer", &Answer{"Ouch I am sensible!"})
}
示例3: custom
// If a parser is known for the specific data type it is
// automatically used.
func custom(conn *golem.Connection, data string) {
fmt.Println("Custom:", data)
conn.Emit("custom", "Custom handler use to receive data.")
}
示例4: nodata
// Event but no data transmission
func nodata(conn *golem.Connection) {
fmt.Println("Nodata: Event triggered.")
conn.Emit("json", &ChatMessage{"Hi from nodata!"})
}
示例5: raw
// If a function accepts a byte array the data is directly
// forwarded to the function without any parsing involved.
// Hence it is the fastest way.
func raw(conn *golem.Connection, data interface{}) {
fmt.Println("Raw: ", string(data.([]byte)))
conn.Emit("raw", []byte("Raw byte array received."))
}
示例6: json
// Function taken special data type and utilizing golem's
// inbuilt unmarshalling
func json(conn *golem.Connection, data *ChatMessage) {
fmt.Println("JSON: ", data.Msg)
conn.Emit("json", &data)
}
示例7: echo
func echo(conn *golem.Connection, data *EchoMessage) {
log.Print("Echo message received.")
conn.Emit("echo", &data.Msg)
}