package libnmdc import ( "fmt" ) func ExampleHubConnectionOptions_Connect() { opts := HubConnectionOptions{ Address: "127.0.0.1", Self: *NewUserInfo("slowpoke9"), } hub := opts.Connect() for { event := <-hub.OnEvent switch event.EventType { case EVENT_CONNECTION_STATE_CHANGED: fmt.Printf("Connection -- %s (%s)\n", event.StateChange, event.Message) case 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) } } } func ExampleHubConnectionOptions_ConnectSync() { cb := func(hub *HubConnection, event HubEvent) { switch event.EventType { case EVENT_CONNECTION_STATE_CHANGED: fmt.Printf("Connection -- %s (%s)\n", event.StateChange, event.Message) case 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) } } opts := HubConnectionOptions{ Address: "127.0.0.1", Self: *NewUserInfo("slowpoke9"), OnEventSync: cb, } opts.ConnectSync() // blocking }