sample: add a version using the synchronous API

This commit is contained in:
mappu 2016-11-29 19:30:33 +13:00
parent bd0425d6d4
commit 231bfeb247
2 changed files with 38 additions and 0 deletions

View File

@ -2,6 +2,7 @@
// This sample file demonstrates use of the libnmdc.go library. It's excluded
// when building the library package, but you can run it via `go run libnmdc_sample.go`.
// This version demonstrates the channel API.
package main

37
libnmdc_sample2.go Normal file
View File

@ -0,0 +1,37 @@
// +build ignore
// This sample file demonstrates use of the libnmdc.go library. It's excluded
// when building the library package, but you can run it via `go run libnmdc_sample.go`.
// This version demonstrates the sync API.
package main
import (
"fmt"
"libnmdc"
)
func main() {
libnmdc.HubConnectionOptions{
Address: "127.0.0.1",
Self: libnmdc.NewUserInfo("slowpoke9"),
OnEventSync: func(ev libnmdc.HubEvent) {
switch event.EventType {
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
fmt.Printf("Connection -- %s (%s)\n", event.StateChange.Format(), event.Message)
case libnmdc.EVENT_PUBLIC:
fmt.Printf("Message from '%s': '%s'\n", event.Nick, event.Message)
if event.Message == "how are you" {
hub.SayPublic("good thanks!")
}
default:
fmt.Printf("%+v\n", event)
}
},
}.Connect()
}