func hello(conn *golem.Connection, data *Hello) { fmt.Println("Hello from", data.From, "to", data.To) conn.Emit("answer", &Answer{"Thanks, client!"}) }
func poke(conn *golem.Connection) { fmt.Println("Poke-Event triggered!") conn.Emit("answer", &Answer{"Ouch I am sensible!"}) }
// 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.") }
// Event but no data transmission func nodata(conn *golem.Connection) { fmt.Println("Nodata: Event triggered.") conn.Emit("json", &ChatMessage{"Hi from nodata!"}) }
// 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.")) }
// 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) }