本文整理汇总了Golang中github.com/smancke/guble/client.Client.WriteRawMessage方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.WriteRawMessage方法的具体用法?Golang Client.WriteRawMessage怎么用?Golang Client.WriteRawMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/smancke/guble/client.Client
的用法示例。
在下文中一共展示了Client.WriteRawMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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")
}
}()
}
}