本文整理汇总了Golang中github.com/smancke/guble/client.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeLoop
func writeLoop(client *client.Client) {
shouldStop := false
for !shouldStop {
func() {
defer guble.PanicLogger()
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
if strings.TrimSpace(text) == "" {
return
}
if strings.TrimSpace(text) == "?" || strings.TrimSpace(text) == "help" {
printHelp()
return
}
if strings.HasPrefix(text, ">") {
fmt.Print("header: ")
header, _ := reader.ReadString('\n')
text += header
fmt.Print("body: ")
body, _ := reader.ReadString('\n')
text += strings.TrimSpace(body)
}
if args.Verbose {
log.Printf("Sending: %v\n", text)
}
if err := client.WriteRawMessage([]byte(text)); err != nil {
shouldStop = true
guble.Err(err.Error())
}
}()
}
}
示例2: readLoop
func readLoop(client client.Client) {
for {
select {
case incomingMessage := <-client.Messages():
if *verbose {
fmt.Println(string(incomingMessage.Bytes()))
} else {
fmt.Printf("%v: %v\n", incomingMessage.UserID, incomingMessage.BodyAsString())
}
case e := <-client.Errors():
fmt.Println("ERROR: " + string(e.Bytes()))
case status := <-client.StatusMessages():
fmt.Println(string(status.Bytes()))
fmt.Println()
}
}
}
示例3: readLoop
func readLoop(client *client.Client) {
for {
select {
case incomingMessage := <-client.Messages():
if args.Verbose {
fmt.Println(string(incomingMessage.Bytes()))
} else {
fmt.Printf("%v: %v\n", incomingMessage.PublisherUserId, incomingMessage.BodyAsString())
}
case error := <-client.Errors():
fmt.Println("ERROR: " + string(error.Bytes()))
case status := <-client.StatusMessages():
fmt.Println(string(status.Bytes()))
fmt.Println()
}
}
}
示例4: expectStatusMessage
func expectStatusMessage(t *testing.T, client *client.Client, name string, arg string) string {
select {
case notify := <-client.StatusMessages():
assert.Equal(t, name, notify.Name)
assert.Equal(t, arg, notify.Arg)
return notify.Json
case <-time.After(time.Second * 1):
t.Logf("no notification of type %s after 1 second", name)
t.Fail()
return ""
}
}
示例5: writeLoop
func writeLoop(client client.Client) {
shouldStop := false
for !shouldStop {
func() {
defer protocol.PanicLogger()
reader := bufio.NewReader(os.Stdin)
text, err := reader.ReadString('\n')
if err != nil {
return
}
if strings.TrimSpace(text) == "" {
return
}
if strings.TrimSpace(text) == "?" || strings.TrimSpace(text) == "help" {
printHelp()
return
}
if strings.HasPrefix(text, ">") {
fmt.Print("header: ")
header, err := reader.ReadString('\n')
if err != nil {
return
}
text += header
fmt.Print("body: ")
body, err := reader.ReadString('\n')
if err != nil {
return
}
text += strings.TrimSpace(body)
}
if *verbose {
log.Printf("Sending: %v\n", text)
}
if err := client.WriteRawMessage([]byte(text)); err != nil {
shouldStop = true
logger.WithError(err).Error("Error on Writing message")
}
}()
}
}
示例6: sendMessageSample
func sendMessageSample(c client.Client) error {
return c.Send("topic", "personalized offer", "{id:id}")
}
示例7: sendBroadcastSample
func sendBroadcastSample(c client.Client) error {
return c.Send("/gcm/broadcast", "general offer", "{id:id}")
}
示例8: sendMessageSample
func sendMessageSample(c client.Client) error {
return c.Send(testTopic, "test-body", "{id:id}")
}