• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang logmessage.ParseMessage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestAddingForAnotherApp

func TestAddingForAnotherApp(t *testing.T) {
	store := NewMessageStore(2)

	appId := "myApp"
	message, err := logmessage.ParseMessage(testhelpers.MarshalledLogMessage(t, "Message", appId))
	assert.NoError(t, err)
	store.Add(message, appId)

	anotherAppId := "anotherApp"
	anotherAppMessage, err := logmessage.ParseMessage(testhelpers.MarshalledLogMessage(t, "AnotherAppMessage", anotherAppId))
	assert.NoError(t, err)
	store.Add(anotherAppMessage, anotherAppId)

	messages, err := testhelpers.ParseDumpedMessages(store.DumpFor(appId))
	assert.NoError(t, err)

	assert.Equal(t, len(messages), 1)
	assert.Equal(t, message.GetRawMessage(), messages[0])

	messages, err = testhelpers.ParseDumpedMessages(store.DumpFor(anotherAppId))
	assert.NoError(t, err)

	assert.Equal(t, len(messages), 1)
	assert.Equal(t, anotherAppMessage.GetRawMessage(), messages[0])
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:25,代码来源:message_store_test.go


示例2: logMessageWithTime

func logMessageWithTime(t *testing.T, messageString string, timestamp int64) *logmessage.Message {
	data, err := proto.Marshal(generateMessage(messageString, timestamp))
	assert.NoError(t, err)
	message, err := logmessage.ParseMessage(data)
	assert.NoError(t, err)

	return message
}
开发者ID:pmuellr,项目名称:cli,代码行数:8,代码来源:log_message_queue_test.go


示例3: logMessageWithTime

func logMessageWithTime(messageString string, timestamp int) *logmessage.Message {
	data, err := proto.Marshal(generateMessage(messageString, int64(timestamp)))
	Expect(err).NotTo(HaveOccurred())
	message, err := logmessage.ParseMessage(data)
	Expect(err).NotTo(HaveOccurred())

	return message
}
开发者ID:knolleary,项目名称:cli,代码行数:8,代码来源:log_message_queue_test.go


示例4: TestThatItWorksLikeAChannel

func TestThatItWorksLikeAChannel(t *testing.T) {
	inMessageChan := make(chan *logmessage.Message)
	outMessageChan := make(chan *logmessage.Message, 2)
	go OverwritingMessageChannel(inMessageChan, outMessageChan, nil)

	logMessage1, err := logmessage.ParseMessage(testhelpers.MarshalledLogMessage(t, "message 1", "appId"))
	assert.NoError(t, err)
	inMessageChan <- logMessage1
	readMessage := <-outMessageChan
	assert.Contains(t, string(readMessage.GetRawMessage()), "message 1")

	logMessage2, err := logmessage.ParseMessage(testhelpers.MarshalledLogMessage(t, "message 2", "appId"))
	assert.NoError(t, err)
	inMessageChan <- logMessage2
	readMessage2 := <-outMessageChan
	assert.Contains(t, string(readMessage2.GetRawMessage()), "message 2")

}
开发者ID:narayana1208,项目名称:loggregator,代码行数:18,代码来源:overwriting_message_channel_test.go


示例5: TestRecentLogsFor

func TestRecentLogsFor(t *testing.T) {
	// out of order messages we will send
	messagesSent := [][]byte{
		marshalledLogMessageWithTime(t, "My message", int64(3000)),
	}

	websocketEndpoint := func(conn *websocket.Conn) {
		request := conn.Request()
		assert.Equal(t, request.URL.Path, "/dump/")
		assert.Equal(t, request.URL.RawQuery, "app=my-app-guid")
		assert.Equal(t, request.Method, "GET")
		assert.Contains(t, request.Header.Get("Authorization"), "BEARER my_access_token")

		for _, msg := range messagesSent {
			conn.Write(msg)
		}
		time.Sleep(time.Duration(2) * time.Second)
		conn.Close()
	}
	websocketServer := httptest.NewTLSServer(websocket.Handler(websocketEndpoint))
	defer websocketServer.Close()

	expectedMessage, err := logmessage.ParseMessage(messagesSent[0])
	assert.NoError(t, err)

	app := cf.Application{Name: "my-app", Guid: "my-app-guid"}
	config := &configuration.Configuration{AccessToken: "BEARER my_access_token", Target: "https://localhost"}

	endpointRepo := &testapi.FakeEndpointRepo{GetEndpointEndpoints: map[cf.EndpointType]string{
		cf.LoggregatorEndpointKey: strings.Replace(websocketServer.URL, "https", "wss", 1),
	}}

	logsRepo := NewLoggregatorLogsRepository(config, endpointRepo)

	connected := false
	onConnect := func() {
		connected = true
	}

	logChan := make(chan *logmessage.Message, 1000)
	err = logsRepo.RecentLogsFor(app, onConnect, logChan)

	// ordered messages we expect to receive
	dumpedMessages := []*logmessage.Message{}
	for msg := range logChan {
		dumpedMessages = append(dumpedMessages, msg)
	}

	assert.NoError(t, err)

	assert.Equal(t, len(dumpedMessages), 1)
	assert.Equal(t, dumpedMessages[0].GetShortSourceTypeName(), expectedMessage.GetShortSourceTypeName())
	assert.Equal(t, dumpedMessages[0].GetLogMessage().GetMessage(), expectedMessage.GetLogMessage().GetMessage())
	assert.Equal(t, dumpedMessages[0].GetLogMessage().GetMessageType(), expectedMessage.GetLogMessage().GetMessageType())
}
开发者ID:jalateras,项目名称:cli,代码行数:55,代码来源:logs_test.go


示例6: parseMessages

func (sinkServer *sinkServer) parseMessages(incomingProtobufChan <-chan []byte) {
	for {
		data := <-incomingProtobufChan
		message, err := logmessage.ParseMessage(data)
		if err != nil {
			sinkServer.logger.Error(fmt.Sprintf("Log message could not be unmarshaled. Dropping it... Error: %v. Data: %v", err, data))
			continue
		}
		sinkServer.parsedMessageChan <- message
	}
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:11,代码来源:sink_server.go


示例7: createMessage

func createMessage(t *testing.T, protoMsg *logmessage.LogMessage, sourceName *string, msgType *logmessage.LogMessage_MessageType) (msg *logmessage.Message) {
	protoMsg.SourceName = sourceName
	protoMsg.MessageType = msgType

	data, err := proto.Marshal(protoMsg)
	assert.NoError(t, err)

	msg, err = logmessage.ParseMessage(data)
	assert.NoError(t, err)

	return
}
开发者ID:nsnt,项目名称:cli,代码行数:12,代码来源:helpers_test.go


示例8: createMessage

func createMessage(protoMsg *logmessage.LogMessage, sourceName *string, msgType *logmessage.LogMessage_MessageType) (msg *logmessage.Message) {
	protoMsg.SourceName = sourceName
	protoMsg.MessageType = msgType

	data, err := proto.Marshal(protoMsg)
	Expect(err).NotTo(HaveOccurred())

	msg, err = logmessage.ParseMessage(data)
	Expect(err).NotTo(HaveOccurred())

	return
}
开发者ID:knolleary,项目名称:cli,代码行数:12,代码来源:helpers_test.go


示例9: TestThatItSendsStdErrAsErr

func TestThatItSendsStdErrAsErr(t *testing.T) {
	sink, err := NewSyslogSink("appId", "syslog://localhost:24631", testhelpers.Logger())
	assert.NoError(t, err)
	closeChan := make(chan Sink)
	go sink.Run(closeChan)
	logMessage, err := logmessage.ParseMessage(testhelpers.MarshalledErrorLogMessage(t, "err", "appId"))
	assert.NoError(t, err)
	sink.Channel() <- logMessage
	data := <-dataReadChannel
	assert.Contains(t, string(data), "<3>")
	assert.Contains(t, string(data), "appId")
	assert.Contains(t, string(data), "err")
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:13,代码来源:syslog_sink_test.go


示例10: TestOnlyDumpsMessagesThatHaveALength

// This test exists because the ring buffer will dump messages
// that actually exist.
func TestOnlyDumpsMessagesThatHaveALength(t *testing.T) {
	store := NewMessageStore(2)

	target := "appId"
	message, err := logmessage.ParseMessage(testhelpers.MarshalledLogMessage(t, "Hello world", target))
	assert.NoError(t, err)
	store.Add(message, target)

	messages, err := testhelpers.ParseDumpedMessages(store.DumpFor(target))
	assert.NoError(t, err)

	assert.Equal(t, len(messages), 1)
	assert.Equal(t, messages[0], message.GetRawMessage())
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:16,代码来源:message_store_test.go


示例11: NewLogMessage

func NewLogMessage(msgText, appGuid, sourceName string, timestamp time.Time) (msg *logmessage.Message) {
	messageType := logmessage.LogMessage_ERR

	logMsg := logmessage.LogMessage{
		Message:     []byte(msgText),
		AppId:       proto.String(appGuid),
		MessageType: &messageType,
		SourceName:  proto.String(sourceName),
		Timestamp:   proto.Int64(timestamp.UnixNano()),
	}
	data, _ := proto.Marshal(&logMsg)
	msg, _ = logmessage.ParseMessage(data)

	return
}
开发者ID:nsnt,项目名称:cli,代码行数:15,代码来源:helpers.go


示例12: listenForMessages

func (repo LoggregatorLogsRepository) listenForMessages(ws *websocket.Conn, msgChan chan<- *logmessage.Message) {
	for {
		var data []byte
		err := websocket.Message.Receive(ws, &data)
		if err != nil {
			break
		}

		msg, msgErr := logmessage.ParseMessage(data)
		if msgErr != nil {
			continue
		}
		msgChan <- msg
	}
}
开发者ID:knolleary,项目名称:cli,代码行数:15,代码来源:logs.go


示例13: TestThatItSendsStdErrAsErr

func TestThatItSendsStdErrAsErr(t *testing.T) {
	sysLogger := NewSyslogWriter("syslog", "localhost:24632", "appId", false)
	sink := NewSyslogSink("appId", "syslog://localhost:24632", loggertesthelper.Logger(), sysLogger, make(chan *logmessage.Message))
	go sink.Run()
	defer close(sink.Channel())

	logMessage, err := logmessage.ParseMessage(messagetesthelpers.MarshalledErrorLogMessage(t, "err", "appId"))
	assert.NoError(t, err)

	sink.Channel() <- logMessage
	data := <-fakeSyslogServer2.dataReadChannel

	assert.Contains(t, string(data), "<11>1")
	assert.Contains(t, string(data), "appId")
	assert.Contains(t, string(data), "err")
}
开发者ID:pxie,项目名称:loggregator,代码行数:16,代码来源:syslog_sink_test.go


示例14: logsFor

func (l *FakeLogsRepository) logsFor(app cf.Application, logMessages []logmessage.LogMessage, onConnect func(), logChan chan *logmessage.Message, stopLoggingChan chan bool) {
	l.AppLogged = app
	onConnect()
	for _, logMsg := range logMessages {
		data, _ := proto.Marshal(&logMsg)
		msg, _ := logmessage.ParseMessage(data)
		logChan <- msg
	}

	close(logChan)

	go func() {
		l.TailLogStopCalled = <-stopLoggingChan
	}()

	return
}
开发者ID:jalateras,项目名称:cli,代码行数:17,代码来源:fake_logs_repository.go


示例15: TestRegisterAndFor

func TestRegisterAndFor(t *testing.T) {
	store := NewMessageStore(2)

	appId := "myApp"
	appMessageString := "AppMessage"
	appMessage := testhelpers.MarshalledLogMessage(t, appMessageString, "myApp")
	message, err := logmessage.ParseMessage(appMessage)

	store.Add(message, appId)

	messages, err := testhelpers.ParseDumpedMessages(store.DumpFor(appId))
	assert.NoError(t, err)

	assert.Equal(t, len(messages), 1)

	testhelpers.AssertProtoBufferMessageEquals(t, appMessageString, messages[0])
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:17,代码来源:message_store_test.go


示例16: logMessageWithTime

func logMessageWithTime(t *testing.T, messageString string, timestamp int64) *logmessage.Message {
	messageType := logmessage.LogMessage_OUT
	sourceType := logmessage.LogMessage_DEA
	logMessage := &logmessage.LogMessage{
		Message:     []byte(messageString),
		AppId:       proto.String("my-app-guid"),
		MessageType: &messageType,
		SourceType:  &sourceType,
		Timestamp:   proto.Int64(timestamp),
	}

	data, err := proto.Marshal(logMessage)
	assert.NoError(t, err)
	message, err := logmessage.ParseMessage(data)
	assert.NoError(t, err)

	return message
}
开发者ID:jalateras,项目名称:cli,代码行数:18,代码来源:log_message_queue_test.go


示例17: listenForMessages

func (cnsmr *consumer) listenForMessages(msgChan chan<- *logmessage.LogMessage) error {
	defer cnsmr.ws.Close()

	for {
		var data []byte

		_, data, err := cnsmr.ws.ReadMessage()
		if err != nil {
			return err
		}

		msg, msgErr := logmessage.ParseMessage(data)
		if msgErr != nil {
			continue
		}

		msgChan <- msg.GetLogMessage()
	}
}
开发者ID:Reejoshi,项目名称:cli,代码行数:19,代码来源:consumer.go


示例18: TestRecentLogsFor

func TestRecentLogsFor(t *testing.T) {
	expectedMessage := messagetesthelpers.MarshalledLogMessage(t, "My message", "my-app-id")
	message, err := logmessage.ParseMessage(expectedMessage)
	assert.NoError(t, err)

	ts := httptest.NewTLSServer(http.HandlerFunc(recentLogsEndpoint(message)))
	defer ts.Close()

	app := cf.Application{Name: "my-app", Guid: "my-app-guid"}
	config := &configuration.Configuration{AccessToken: "BEARER my_access_token", Target: ts.URL}
	gateway := net.NewCloudControllerGateway(&testhelpers.FakeAuthenticator{})
	loggregatorHostResolver := func(hostname string) string { return hostname }
	logsRepo := NewLoggregatorLogsRepository(config, gateway, loggregatorHostResolver)

	logs, err := logsRepo.RecentLogsFor(app)
	assert.NoError(t, err)

	assert.Equal(t, len(logs), 1)
	actualMessage, err := proto.Marshal(logs[0])
	assert.NoError(t, err)
	assert.Equal(t, actualMessage, expectedMessage)
}
开发者ID:jbayer,项目名称:cli,代码行数:22,代码来源:logs_test.go


示例19:

		})

		Context("with a read timeout set", func() {
			It("does not wait forever", func(done Done) {
				err := l.Start(fmt.Sprintf("ws://%s", ts.Listener.Addr()), "myApp", outputChan, stopChan)
				Expect(err).To(HaveOccurred())

				close(done)
			})

			It("sends an error message to the channel", func(done Done) {
				l.Start(fmt.Sprintf("ws://%s", ts.Listener.Addr()), "myApp", outputChan, stopChan)
				var msgData []byte
				Eventually(outputChan).Should(Receive(&msgData))

				msg, _ := logmessage.ParseMessage(msgData)
				Expect(msg.GetLogMessage().GetSourceName()).To(Equal("LGR"))
				Expect(string(msg.GetLogMessage().GetMessage())).To(Equal("WebsocketListener.Start: Timed out listening to a doppler server after 500ms"))
				close(done)
			})
		})

		Context("without a read timeout", func() {
			It("waits for messages to come in", func() {
				converter := func(d []byte) ([]byte, error) { return d, nil }
				l = listener.NewWebsocket(marshaller.LoggregatorLogMessage, converter, 0, handshakeTimeout, mockBatcher, loggertesthelper.Logger())

				go l.Start(fmt.Sprintf("ws://%s", ts.Listener.Addr()), "myApp", outputChan, stopChan)

				go func() {
					time.Sleep(750 * time.Millisecond)
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:31,代码来源:websocket_listener_test.go


示例20: logMessageForBenchmark

func logMessageForBenchmark(b *testing.B, messageString string, timestamp int64) *logmessage.Message {
	data, _ := proto.Marshal(generateMessage(messageString, timestamp))
	message, _ := logmessage.ParseMessage(data)
	return message
}
开发者ID:pmuellr,项目名称:cli,代码行数:5,代码来源:log_message_queue_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang logmessage.LogMessage类代码示例发布时间:2022-05-23
下一篇:
Golang logmessage.NewMessage函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap