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