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


Golang messages.Client类代码示例

本文整理汇总了Golang中github.com/apoydence/talaria/messages.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: fetchFile

func (b *Broker) fetchFile(controller Controller, message *messages.Client, conn *websocket.Conn) {
	fetchFile := message.GetFetchFile()
	err := controller.FetchFile(fetchFile.GetFileId(), fetchFile.GetName())
	if err != nil && err.Uri == "" {
		b.writeError(err.Error(), message, conn)
		return
	}

	b.writeFileLocation(err, message, conn)
}
开发者ID:jmptrader,项目名称:talaria,代码行数:10,代码来源:broker.go

示例2: writeMessage

func (c *Connection) writeMessage(msg *messages.Client) {
	data, err := msg.Marshal()
	if err != nil {
		c.log.Panic("Unable to marshal message", err)
	}

	if err = c.conn.WriteMessage(websocket.BinaryMessage, data); err != nil {
		c.writeError(err)
		return
	}
}
开发者ID:jmptrader,项目名称:talaria,代码行数:11,代码来源:connection.go

示例3: writeReadData

func (b *Broker) writeReadData(data []byte, message *messages.Client, conn *websocket.Conn) {
	msgType := messages.Server_ReadData
	server := &messages.Server{
		MessageType: &msgType,
		MessageId:   proto.Uint64(message.GetMessageId()),
		ReadData: &messages.ReadData{
			Data: data,
		},
	}
	b.writeMessage(server, conn)
}
开发者ID:jmptrader,项目名称:talaria,代码行数:11,代码来源:broker.go

示例4: writeFileOffset

func (b *Broker) writeFileOffset(offset int64, message *messages.Client, conn *websocket.Conn) {
	msgType := messages.Server_FileOffset
	server := &messages.Server{
		MessageType: &msgType,
		MessageId:   proto.Uint64(message.GetMessageId()),
		FileOffset: &messages.FileOffset{
			Offset: proto.Int64(offset),
		},
	}
	b.writeMessage(server, conn)
}
开发者ID:jmptrader,项目名称:talaria,代码行数:11,代码来源:broker.go

示例5: writeError

func (b *Broker) writeError(errStr string, message *messages.Client, conn *websocket.Conn) {
	msgType := messages.Server_Error
	server := &messages.Server{
		MessageType: &msgType,
		MessageId:   proto.Uint64(message.GetMessageId()),
		Error: &messages.Error{
			Message: proto.String(errStr),
		},
	}
	b.writeMessage(server, conn)
}
开发者ID:jmptrader,项目名称:talaria,代码行数:11,代码来源:broker.go

示例6: readMessage

func (m *mockServer) readMessage(conn *websocket.Conn) *messages.Client {
	_, data, err := conn.ReadMessage()
	if err != nil {
		return nil
	}

	var msg messages.Client
	err = msg.Unmarshal(data)
	Expect(err).ToNot(HaveOccurred())
	return &msg
}
开发者ID:jmptrader,项目名称:talaria,代码行数:11,代码来源:mock_server_test.go

示例7: writeFileLocation

func (b *Broker) writeFileLocation(fetchFileErr *FetchFileError, message *messages.Client, conn *websocket.Conn) {
	var uri string
	if fetchFileErr != nil {
		uri = fetchFileErr.Uri
	}

	msgType := messages.Server_FileLocation
	server := &messages.Server{
		MessageType: &msgType,
		MessageId:   proto.Uint64(message.GetMessageId()),
		FileLocation: &messages.FileLocation{
			Local: proto.Bool(uri == ""),
			Uri:   proto.String(uri),
		},
	}
	b.writeMessage(server, conn)
}
开发者ID:jmptrader,项目名称:talaria,代码行数:17,代码来源:broker.go

示例8:

			server.Close()
		})

		It("returns an error", func(done Done) {
			defer close(done)

			mockServer.serverCh <- buildError(99, "some-error")

			go func() {
				defer GinkgoRecover()
				err := connection.FetchFile(9, "some-file")
				Expect(err).ToNot(BeNil())
				Expect(err.Error()).To(Equal("some-error"))
			}()

			var clientMsg *messages.Client
			Eventually(mockServer.clientCh).Should(Receive(&clientMsg))
			Expect(clientMsg.GetMessageType()).To(Equal(messages.Client_FetchFile))
			Expect(clientMsg.FetchFile.GetName()).To(Equal("some-file"))
			Expect(clientMsg.FetchFile.GetFileId()).To(BeEquivalentTo(9))
		})

		It("returns the file ID", func(done Done) {
			defer close(done)

			mockServer.serverCh <- buildFileLocation(99)

			go func() {
				defer GinkgoRecover()
				err := connection.FetchFile(9, "some-file")
				Expect(err).To(BeNil())
开发者ID:jmptrader,项目名称:talaria,代码行数:31,代码来源:connection_test.go

示例9:

			}

			var wg sync.WaitGroup
			defer wg.Wait()
			wg.Add(len(mockServers))
			for i := range mockServers {
				go func(iter int) {
					defer GinkgoRecover()
					defer wg.Done()
					_, err := client.FetchFile(fmt.Sprintf("some-file-%d", iter))
					Expect(err).ToNot(HaveOccurred())
				}(i)
			}

			for i, server := range mockServers {
				var msg *messages.Client
				Eventually(server.clientCh).Should(Receive(&msg))
				Expect(msg.GetMessageType()).To(Equal(messages.Client_FetchFile))
				Expect(msg.GetFetchFile().GetName()).To(Equal(fmt.Sprintf("some-file-%d", i)))
			}
		}, 5)

		It("re-fetches a file if it is redirected", func(done Done) {
			defer close(done)
			mockServers[0].serverCh <- buildRemoteFileLocation(1, servers[1].URL)
			mockServers[1].serverCh <- buildFileLocation(1)

			_, err := client.FetchFile("some-file-1")
			Expect(err).ToNot(HaveOccurred())

			var msg *messages.Client
开发者ID:jmptrader,项目名称:talaria,代码行数:31,代码来源:client_test.go


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