本文整理匯總了Golang中github.com/trevex/golem.Connection類的典型用法代碼示例。如果您正苦於以下問題:Golang Connection類的具體用法?Golang Connection怎麽用?Golang Connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Connection類的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)
}