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) NewCloudEventV2() (*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" )
const APISchemaVersion = "1.0"
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 { // example: 1.0 Version string `json:"version" example:"1.0"` Values []DataValue `json:"values"` }
Data
Array of JSON objects defining the information for the event.
Example: ```go
{ "version": "v1.0", "values": [{ "ResourceAddress": "/sync/sync-status/sync-state", "data_type": "notification", "value_type": "enumeration", "value": "ACQUIRING-SYNC" }, { "ResourceAddress": "/sync/sync-status/sync-state", "data_type": "metric", "value_type": "decimal64.3", "value": 100.3 } }] }
```
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 { // The resource address specifies the Event Producer with a hierarchical path. Currently hierarchical paths with wild cards are not supported. // example: /east-edge-10/Node3/sync/sync-status/sync-state Resource string `json:"ResourceAddress" example:"/east-edge-10/Node3/sync/sync-status/sync-state"` // Type of value object. ( notification | metric) // example: notification DataType DataType `json:"data_type" example:"notification"` // The type format of the value property. // example: enumeration ValueType ValueType `json:"value_type" example:"enumeration"` // value in value_type format. // example: HOLDOVER Value interface{} `json:"value" example:"HOLDOVER"` }
DataValue
A json array of values defining the event.
Example: ```go
{ "ResourceAddress": "/cluster/node/ptp", "data_type": "notification", "value_type": "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": [{ "ResourceAddress": "/sync/sync-status/sync-state", "data_type": "notification", "value_type": "enumeration", "value": "ACQUIRING-SYNC" }, { "ResourceAddress": "/sync/sync-status/sync-state", "data_type": "metric", "value_type": "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) NewCloudEventV2 ¶ added in v1.20.0
func (e *Event) NewCloudEventV2() (*cloudevent.Event, error)
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().