cloudevent

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Overview

Package cloudevent provides types for working with CloudEvents.

Index

Constants

View Source
const (
	// TypeStatus is the event type for status updates.
	TypeStatus = "dimo.status"

	// TypeFingerprint is the event type for fingerprint updates.
	TypeFingerprint = "dimo.fingerprint"

	// TypeVerifableCredential is the event type for verifiable credentials.
	TypeVerifableCredential = "dimo.verifiablecredential" //nolint:gosec // This is not a credential.

	// TypeUnknown is the event type for unknown events.
	TypeUnknown = "dimo.unknown"

	// SpecVersion is the version of the CloudEvents spec.
	SpecVersion = "1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudEvent

type CloudEvent[A any] struct {
	CloudEventHeader
	// Data contains domain-specific information about the event.
	Data A `json:"data"`
}

CloudEvent represents an event according to the CloudEvents spec. To Add extra headers to the CloudEvent, add them to the Extras map. See https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md

func (CloudEvent[A]) MarshalJSON added in v0.3.4

func (c CloudEvent[A]) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for CloudEventHeader

func (*CloudEvent[A]) UnmarshalJSON added in v0.3.4

func (c *CloudEvent[A]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for CloudEvent.

type CloudEventHeader

type CloudEventHeader struct {
	// ID is an identifier for the event. The combination of ID and Source must
	// be unique.
	ID string `json:"id"`

	// Source is the context in which the event happened. In a distributed system it might consist of multiple Producers.
	Source string `json:"source"`

	// Producer is a specific instance, process or device that creates the data structure describing the CloudEvent.
	Producer string `json:"producer"`

	// SpecVersion is the version of CloudEvents specification used.
	// This is always hardcoded "1.0".
	SpecVersion string `json:"specversion"`

	// Subject is an optional field identifying the subject of the event within
	// the context of the event producer. In practice, we always set this.
	Subject string `json:"subject"`

	// Time is an optional field giving the time at which the event occurred. In
	// practice, we always set this.
	Time time.Time `json:"time"`

	// Type describes the type of event. It should generally be a reverse-DNS
	// name.
	Type string `json:"type"`

	// DataContentType is an optional MIME type for the data field. We almost
	// always serialize to JSON and in that case this field is implicitly
	// "application/json".
	DataContentType string `json:"datacontenttype,omitempty"`

	// DataSchema is an optional URI pointing to a schema for the data field.
	DataSchema string `json:"dataschema,omitempty"`

	// DataVersion is the version of the data type.
	DataVersion string `json:"dataversion,omitempty"`

	// Extras contains any additional fields that are not part of the CloudEvent excluding the data field.
	Extras map[string]any `json:"-"`
}

CloudEventHeader contains the metadata for any CloudEvent. To add extra headers to the CloudEvent, add them to the Extras map.

func (*CloudEventHeader) Equals added in v0.3.4

func (c *CloudEventHeader) Equals(other CloudEventHeader) bool

Equals returns true if the two CloudEventHeaders share the same ID and Source.

func (CloudEventHeader) MarshalJSON added in v0.3.4

func (c CloudEventHeader) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for CloudEventHeader

func (*CloudEventHeader) UnmarshalJSON added in v0.3.4

func (c *CloudEventHeader) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for CloudEventHeader.

type Fingerprint added in v0.3.3

type Fingerprint struct {
	VIN string
}

Fingerprint represents a fingerprint message which holds a vehicle's VIN

type FingerprintEvent added in v0.3.3

type FingerprintEvent CloudEvent[Fingerprint]

FingerprintEvent is a CloudEvent for a fingerprint message

type NFTDID added in v0.3.2

type NFTDID struct {
	ChainID         uint64         `json:"chainId"`
	ContractAddress common.Address `json:"contract"`
	TokenID         uint32         `json:"tokenId"`
}

NFTDID is a Decentralized Identifier for NFTs.

func DecodeNFTDID added in v0.3.2

func DecodeNFTDID(did string) (NFTDID, error)

DecodeNFTDID decodes a DID string into a DID struct.

func (NFTDID) String added in v0.3.2

func (d NFTDID) String() string

String returns the string representation of the NFTDID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL