Documentation ¶
Overview ¶
Package event provides primitives to work with CNE specification: https://github.com/redhat-cne/spec.
Index ¶
- Constants
- func ReadDataJSON(out *Data, reader io.Reader) error
- func ReadJSON(out *Event, reader io.Reader) error
- func StringOfApplicationJSON() *string
- func StringOfTextPlain() *string
- func WriteDataJSON(in *Data, writer io.Writer) error
- func WriteJSON(in *Event, writer io.Writer) error
- type Data
- type DataType
- type DataValue
- type Event
- func (e Event) Clone() Event
- func (e *Event) GetCloudNativeEvents(ce *cloudevent.Event) (err error)
- func (e *Event) GetData() *Data
- func (e *Event) GetDataContentType() string
- func (e *Event) GetDataSchema() string
- func (e *Event) GetDataValue() (data []DataValue, err error)
- func (e *Event) GetID() string
- func (e *Event) GetSource() string
- func (e *Event) GetTime() time.Time
- func (e *Event) GetType() string
- func (e Event) JSONString() string
- func (e Event) MarshalJSON() ([]byte, error)
- func (e *Event) NewCloudEvent(ps *pubsub.PubSub) (*cloudevent.Event, error)
- func (e *Event) SetData(data Data)
- func (e *Event) SetDataContentType(ct string)
- func (e *Event) SetDataSchema(s string) error
- func (e *Event) SetDataValue(dataType DataType, obj interface{}) (err error)
- func (e *Event) SetID(id string)
- func (e *Event) SetSource(s string)
- func (e *Event) SetTime(t time.Time)
- func (e *Event) SetType(t string)
- func (e Event) String() string
- func (e *Event) UnmarshalJSON(b []byte) error
- type Reader
- type ValueType
- type Writer
Constants ¶
const ( // TextPlain ... TextPlain = "text/plain" // TextJSON ... TextJSON = "text/json" // ApplicationJSON ... ApplicationJSON = "application/json" )
Variables ¶
This section is empty.
Functions ¶
func StringOfApplicationJSON ¶
func StringOfApplicationJSON() *string
StringOfApplicationJSON returns a string pointer to "application/json"
func StringOfTextPlain ¶
func StringOfTextPlain() *string
StringOfTextPlain returns a string pointer to "text/plain"
func WriteDataJSON ¶
WriteDataJSON writes the in data in the provided writer. Note: this function assumes the input event is valid.
Types ¶
type Data ¶
type Data struct { Version string `json:"version" example:"v1"` Values []DataValue `json:"values"` }
Data ... cloud native events data Data Json payload is as follows,
{ "version": "v1.0", "values": [{ "resource": "/sync/sync-status/sync-state", "dataType": "notification", "valueType": "enumeration", "value": "ACQUIRING-SYNC" }, { "resource": "/sync/sync-status/sync-state", "dataType": "metric", "valueType": "decimal64.3", "value": 100.3 }, { "resource": "/redfish/v1/Systems", "dataType": "notification", "valueType": "redfish-event", "value": { "@odata.context": "/redfish/v1/$metadata#Event.Event", "@odata.type": "#Event.v1_3_0.Event", "Context": "any string is valid", "Events": [{"EventId": "2162", "MemberId": "615703", "MessageId": "TMP0100"}], "Id": "5e004f5a-e3d1-11eb-ae9c-3448edf18a38", "Name": "Event Array" } }] }
func (Data) MarshalJSON ¶
MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.
func (*Data) UnmarshalJSON ¶
UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.
type DataValue ¶
type DataValue struct { Resource string `json:"resource" example:"/cluster/node/clock"` DataType DataType `json:"dataType" example:"metric"` ValueType ValueType `json:"valueType" example:"decimal64.3"` Value interface{} `json:"value" example:"100.3"` }
DataValue ... DataValue Json payload is as follows,
{ "resource": "/cluster/node/ptp", "dataType": "notification", "valueType": "enumeration", "value": "ACQUIRING-SYNC" }
type Event ¶
type Event struct { // ID of the event; must be non-empty and unique within the scope of the producer. // +required ID string `json:"id" example:"789be75d-7ac3-472e-bbbc-6d62878aad4a"` // Type - The type of the occurrence which has happened. // +required Type string `json:"type" example:"event.sync.sync-status.synchronization-state-change"` // Source - The source of the occurrence which has happened. // +required Source string `json:"source" example:"/cluster/node/example.com/ptp/clock_realtime"` // DataContentType - the Data content type // +required DataContentType *string `json:"dataContentType" example:"application/json"` // Time - A Timestamp when the event happened. // +required Time *types.Timestamp `json:"time" example:"2021-02-05T17:31:00Z"` // DataSchema - A link to the schema that the `Data` attribute adheres to. // +optional DataSchema *types.URI `json:"dataSchema,omitempty"` // +required Data *Data `json:"data" ` }
Event represents the canonical representation of a Cloud Native Event. Event Json payload is as follows,
{ "id": "5ce55d17-9234-4fee-a589-d0f10cb32b8e", "type": "event.sync.sync-status.synchronization-state-change", "source": "/cluster/node/example.com/ptp/clock_realtime", "time": "2021-02-05T17:31:00Z", "data": { "version": "v1.0", "values": [{ "resource": "/sync/sync-status/sync-state", "dataType": "notification", "valueType": "enumeration", "value": "ACQUIRING-SYNC" }, { "resource": "/sync/sync-status/sync-state", "dataType": "metric", "valueType": "decimal64.3", "value": 100.3 }] } }
Event request model
func (*Event) GetCloudNativeEvents ¶
func (e *Event) GetCloudNativeEvents(ce *cloudevent.Event) (err error)
GetCloudNativeEvents get event data from cloud events object if its valid else return error
func (*Event) GetDataContentType ¶
GetDataContentType implements Reader.DataContentType
func (*Event) GetDataSchema ¶
GetDataSchema implements Reader.DataSchema
func (*Event) GetDataValue ¶
GetDataValue encodes the given payload
func (Event) JSONString ¶ added in v0.2.0
JSONString returns a pretty-printed representation of the Event.
func (Event) MarshalJSON ¶
MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.
func (*Event) NewCloudEvent ¶
NewCloudEvent create new cloud event from cloud native events and pubsub
func (*Event) SetDataContentType ¶
SetDataContentType implements Writer.SetDataContentType
func (*Event) SetDataSchema ¶
SetDataSchema implements Writer.SetDataSchema
func (*Event) SetDataValue ¶
SetDataValue encodes the given payload
func (*Event) UnmarshalJSON ¶
UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.
type Reader ¶
type Reader interface { // GetType returns event.GetType(). GetType() string // GetTime returns event.GetTime(). GetTime() time.Time // GetID returns event.GetID(). GetID() string // GetDataSchema returns event.GetDataSchema(). GetDataSchema() string // GetDataContentType returns event.GetDataContentType(). GetDataContentType() string // GetData returns event.GetData() GetData() *Data // Clone clones the event . Clone() Event // String returns a pretty-printed representation of the EventContext. String() string }
Reader is the interface for reading through an event from attributes.
type Writer ¶
type Writer interface { // SetType performs event.SetType. SetType(string) // SetID performs event.SetID. SetID(string) // SetTime performs event.SetTime. SetTime(time.Time) // SetDataSchema performs event.SetDataSchema. SetDataSchema(string) error // SetDataContentType performs event.SetDataContentType. SetDataContentType(string) // SetData SetData(Data) }
Writer is the interface for writing through an event onto attributes. If an error is thrown by a sub-component, Writer caches the error internally and exposes errors with a call to event.Validate().