當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Envelope.Error方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/sonde-go/events.Envelope.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Envelope.Error方法的具體用法?Golang Envelope.Error怎麽用?Golang Envelope.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/sonde-go/events.Envelope的用法示例。


在下文中一共展示了Envelope.Error方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SendEvent

func (f *FakeFirehose) SendEvent(eventType events.Envelope_EventType, message string) {
	envelope := events.Envelope{
		Origin:     proto.String("origin"),
		Timestamp:  proto.Int64(1000000000),
		Deployment: proto.String("deployment-name"),
		Job:        proto.String("doppler"),
	}

	switch eventType {
	case events.Envelope_LogMessage:
		envelope.EventType = events.Envelope_LogMessage.Enum()
		envelope.LogMessage = &events.LogMessage{
			Message:     []byte(message),
			MessageType: events.LogMessage_OUT.Enum(),
			Timestamp:   proto.Int64(1000000000),
		}
	case events.Envelope_ValueMetric:
		envelope.EventType = events.Envelope_ValueMetric.Enum()
		envelope.ValueMetric = &events.ValueMetric{
			Name:  proto.String(message),
			Value: proto.Float64(42),
			Unit:  proto.String("unit"),
		}
	case events.Envelope_CounterEvent:
		envelope.EventType = events.Envelope_CounterEvent.Enum()
		envelope.CounterEvent = &events.CounterEvent{
			Name:  proto.String(message),
			Delta: proto.Uint64(42),
		}
	case events.Envelope_ContainerMetric:
		envelope.EventType = events.Envelope_ContainerMetric.Enum()
		envelope.ContainerMetric = &events.ContainerMetric{
			ApplicationId: proto.String(message),
			InstanceIndex: proto.Int32(1),
			CpuPercentage: proto.Float64(1),
			MemoryBytes:   proto.Uint64(1),
			DiskBytes:     proto.Uint64(1),
		}
	case events.Envelope_Error:
		envelope.EventType = events.Envelope_Error.Enum()
		envelope.Error = &events.Error{
			Source:  proto.String("source"),
			Code:    proto.Int32(404),
			Message: proto.String(message),
		}
	case events.Envelope_HttpStart:
		envelope.EventType = events.Envelope_HttpStart.Enum()
		uuid, _ := uuid.NewV4()
		envelope.HttpStart = &events.HttpStart{
			Timestamp:     proto.Int64(12),
			RequestId:     NewUUID(uuid),
			PeerType:      events.PeerType_Client.Enum(),
			Method:        events.Method_GET.Enum(),
			Uri:           proto.String("some uri"),
			RemoteAddress: proto.String("some address"),
			UserAgent:     proto.String(message),
		}
	case events.Envelope_HttpStop:
		envelope.EventType = events.Envelope_HttpStop.Enum()
		uuid, _ := uuid.NewV4()
		envelope.HttpStop = &events.HttpStop{
			Timestamp:     proto.Int64(12),
			Uri:           proto.String("http://stop.example.com"),
			RequestId:     NewUUID(uuid),
			PeerType:      events.PeerType_Client.Enum(),
			StatusCode:    proto.Int32(404),
			ContentLength: proto.Int64(98475189),
		}
	case events.Envelope_HttpStartStop:
		envelope.EventType = events.Envelope_HttpStartStop.Enum()
		uuid, _ := uuid.NewV4()
		envelope.HttpStartStop = &events.HttpStartStop{
			StartTimestamp: proto.Int64(1234),
			StopTimestamp:  proto.Int64(5555),
			RequestId:      NewUUID(uuid),
			PeerType:       events.PeerType_Server.Enum(),
			Method:         events.Method_GET.Enum(),
			Uri:            proto.String("http://startstop.example.com"),
			RemoteAddress:  proto.String("http://startstop.example.com"),
			UserAgent:      proto.String("test"),
			StatusCode:     proto.Int32(1234),
			ContentLength:  proto.Int64(5678),
			ApplicationId:  NewUUID(uuid),
		}

	}

	f.addEvent(envelope)
}
開發者ID:cloudfoundry,項目名稱:firehose-plugin,代碼行數:89,代碼來源:fake_firehose.go


注:本文中的github.com/cloudfoundry/sonde-go/events.Envelope.Error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。