示例#1
0
func hello(conn *golem.Connection, data *Hello) {
	fmt.Println("Hello from", data.From, "to", data.To)
	conn.Emit("answer", &Answer{"Thanks, client!"})
}
示例#2
0
func poke(conn *golem.Connection) {
	fmt.Println("Poke-Event triggered!")
	conn.Emit("answer", &Answer{"Ouch I am sensible!"})
}
示例#3
0
// 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
0
// Event but no data transmission
func nodata(conn *golem.Connection) {
	fmt.Println("Nodata: Event triggered.")
	conn.Emit("json", &ChatMessage{"Hi from nodata!"})
}
示例#5
0
// 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
0
// 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)
}
func echo(conn *golem.Connection, data *EchoMessage) {
	log.Print("Echo message received.")
	conn.Emit("echo", &data.Msg)
}