当前位置: 首页>>代码示例>>Golang>>正文


Golang client.Client类代码示例

本文整理汇总了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())
			}
		}()
	}
}
开发者ID:tkrille,项目名称:guble,代码行数:35,代码来源:main.go

示例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()
		}
	}
}
开发者ID:smancke,项目名称:guble,代码行数:17,代码来源:main.go

示例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()
		}
	}
}
开发者ID:tkrille,项目名称:guble,代码行数:17,代码来源:main.go

示例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 ""
	}
}
开发者ID:tkrille,项目名称:guble,代码行数:12,代码来源:integration_test.go

示例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")
			}
		}()
	}
}
开发者ID:smancke,项目名称:guble,代码行数:44,代码来源:main.go

示例6: sendMessageSample

func sendMessageSample(c client.Client) error {
	return c.Send("topic", "personalized offer", "{id:id}")
}
开发者ID:cosminrentea,项目名称:guble,代码行数:3,代码来源:benchmarking_gcm_test.go

示例7: sendBroadcastSample

func sendBroadcastSample(c client.Client) error {
	return c.Send("/gcm/broadcast", "general offer", "{id:id}")
}
开发者ID:cosminrentea,项目名称:guble,代码行数:3,代码来源:benchmarking_gcm_test.go

示例8: sendMessageSample

func sendMessageSample(c client.Client) error {
	return c.Send(testTopic, "test-body", "{id:id}")
}
开发者ID:smancke,项目名称:guble,代码行数:3,代码来源:benchmarking_common_test.go


注:本文中的github.com/smancke/guble/client.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。