Documentation
¶
Overview ¶
Package cloudevent provides types for working with CloudEvents.
Package types provides event type constants for CloudEvents.
Index ¶
- Constants
- func AddNonColumnFieldsToExtras(event *CloudEventHeader) map[string]any
- func BytesForSignature(ev RawEvent) []byte
- func EncodeLegacyNFTDID(chainID uint64, contractAddress common.Address, tokenID *big.Int) string
- func IsJSONDataContentType(ct string) bool
- func RestoreNonColumnFields(event *CloudEventHeader)
- type CloudEvent
- type CloudEventHeader
- type ERC20DID
- type ERC721DID
- type EthrDID
- type RawEvent
- type StoredEvent
Constants ¶
const ( // TypeStatus is the event type for status updates. TypeStatus = "dimo.status" // TypeStatus is the event type for status updates. TypeRawStatus = "dimo.raw.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. // TypeAttestation is the event type for 3rd party attestations TypeAttestation = "dimo.attestation" // TypeAttestationTombstone is the event type used to tombstone an // attestation. The data payload carries the id of the attestation // being tombstoned in the voidsId field; see the voids_id ClickHouse // column populated from it. TypeAttestationTombstone = "dimo.tombstone" // TypeUnknown is the event type for unknown events. TypeUnknown = "dimo.unknown" // TypeEvent is the event type for multiple signals TypeSignals = "dimo.signals" // TypeEvent is the event type for a single signal TypeSignal = "dimo.signal" // TypeEvent is the event type for multiple events TypeEvents = "dimo.events" // TypeEvent is the event type for a single event TypeEvent = "dimo.event" // TypeTrigger is the event type from a vehicle trigger. TypeTrigger = "dimo.trigger" // TypeSACD is the event type for SACD events. TypeSACD = "dimo.sacd" // TypeSACDTemplate is the event type for SACD template events. TypeSACDTemplate = "dimo.sacd.template" )
const ( // ERC721DIDMethod is the method for a ERC721 NFT DID. ERC721DIDMethod = "erc721" // EthrDIDMethod is the method for a Ethereum Address DID. EthrDIDMethod = "ethr" // ERC20DIDMethod is the method for a ERC20 token DID. ERC20DIDMethod = "erc20" )
const SpecVersion = "1.0"
SpecVersion is the version of the CloudEvents spec.
Variables ¶
This section is empty.
Functions ¶
func AddNonColumnFieldsToExtras ¶ added in v0.2.0
func AddNonColumnFieldsToExtras(event *CloudEventHeader) map[string]any
AddNonColumnFieldsToExtras adds fields without dedicated columns to Extras. Returns nil when there are no extras and no non-column fields to add.
func BytesForSignature ¶ added in v0.1.6
BytesForSignature returns the bytes that were signed (wire form of data or data_base64) for a RawEvent. Use for signature verification; not the same as Data when the CE used data_base64.
func EncodeLegacyNFTDID ¶ added in v0.1.0
EncodeLegacyNFTDID is a legacy encoder for NFT DIDs that use the format "did:nft:1:0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF_1".
func IsJSONDataContentType ¶ added in v0.1.5
IsJSONDataContentType returns true if the MIME type indicates a JSON payload. Matches "application/json" and any "+json" suffix type (e.g. "application/cloudevents+json").
func RestoreNonColumnFields ¶ added in v0.2.0
func RestoreNonColumnFields(event *CloudEventHeader)
RestoreNonColumnFields restores non-column fields from Extras.
Types ¶
type CloudEvent ¶
type CloudEvent[A any] struct { CloudEventHeader // Data contains domain-specific information about the event. Data A `json:"data"` DataBase64 string `json:"data_base64,omitempty"` }
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 ¶
func (c CloudEvent[A]) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling for CloudEvent[A].
func (*CloudEvent[A]) UnmarshalJSON ¶
func (c *CloudEvent[A]) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling for CloudEvent. It transparently handles both "data" and "data_base64" wire formats. For RawEvent (CloudEvent[json.RawMessage]), Data is set to the raw payload bytes.
type CloudEventHeader ¶
type CloudEventHeader struct {
// SpecVersion is the version of CloudEvents specification used.
// This is always hardcoded "1.0".
SpecVersion string `json:"specversion"`
// Type describes the type of event. It should generally be a reverse-DNS
// name.
Type string `json:"type"`
// Source is the context in which the event happened. In a distributed system it might consist of multiple Producers.
Source string `json:"source"`
// 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"`
// ID is an identifier for the event. The combination of ID and Source must
// be unique.
ID string `json:"id"`
// Time is an optional field giving the time at which the event occurred. In
// practice, we always set this.
Time time.Time `json:"time"`
// 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"`
// Producer is a specific instance, process or device that creates the data structure describing the CloudEvent.
Producer string `json:"producer"`
// Signature hold the signature of the a cloudevent's data field.
Signature string `json:"signature,omitempty"`
// RawEventID optionally links a parsed event to the ID of its backing raw event.
RawEventID string `json:"raweventid,omitempty"`
// Tags are a list of tags that can be used to filter events.
Tags []string `json:"tags,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. Field order matches the JSON Event Format: specversion, type, source, subject, id, time, then optional/extension attributes. See https://github.com/cloudevents/spec/blob/main/cloudevents/formats/json-format.md To add extra headers to the CloudEvent, add them to the Extras map.
func DecodeHeader ¶ added in v0.1.6
func DecodeHeader(data []byte) (CloudEventHeader, error)
DecodeHeader parses only the CloudEvent header fields from JSON, skipping the data payload. More efficient than unmarshaling a full event when only metadata is needed (e.g. for scaling).
func (*CloudEventHeader) Equals ¶
func (c *CloudEventHeader) Equals(other CloudEventHeader) bool
Equals returns true if the two CloudEventHeaders share the same IndexKey.
func (CloudEventHeader) Key ¶ added in v0.0.3
func (c CloudEventHeader) Key() string
Key returns the unique identifier for the CloudEvent.
func (CloudEventHeader) MarshalJSON ¶
func (c CloudEventHeader) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling for CloudEventHeader.
func (*CloudEventHeader) UnmarshalJSON ¶
func (c *CloudEventHeader) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling for CloudEventHeader.
type ERC20DID ¶ added in v0.1.0
type ERC20DID struct {
ChainID uint64 `json:"chainId"`
ContractAddress common.Address `json:"contract"`
}
ERC20DID is a Decentralized Identifier for an ERC20 token.
func DecodeERC20DID ¶ added in v0.1.0
DecodeERC20DID decodes a ERC20 DID string into a DID struct.
func (ERC20DID) MarshalText ¶ added in v0.1.1
MarshalText implements encoding.TextMarshaler
func (*ERC20DID) UnmarshalText ¶ added in v0.1.1
UnmarshalText implements encoding.TextUnmarshaler
type ERC721DID ¶ added in v0.1.0
type ERC721DID struct {
ChainID uint64 `json:"chainId"`
ContractAddress common.Address `json:"contract"`
TokenID *big.Int `json:"tokenId"`
}
ERC721DID is a Decentralized Identifier for a ERC721 NFT.
func DecodeERC721DID ¶ added in v0.1.0
DecodeERC721DID decodes a DID string into a DID struct.
func DecodeERC721orNFTDID ¶ added in v0.1.0
DecodeERC721orNFTDID is a decoder that attempts to decode a DID string into an ERC721DID or a legacy NFT DID.
func DecodeLegacyNFTDID ¶ added in v0.1.0
DecodeLegacyNFTDID is a legacy decoder for NFT DIDs that use the format "did:nft:1:0xbA5738a18d83D41847dfFbDC6101d37C69c9B0cF_1" You most likely want to use DecodeERC721DID instead.
func (ERC721DID) MarshalText ¶ added in v0.1.1
MarshalText implements encoding.TextMarshaler
func (*ERC721DID) UnmarshalText ¶ added in v0.1.1
UnmarshalText implements encoding.TextUnmarshaler
type EthrDID ¶
type EthrDID struct {
ChainID uint64 `json:"chainId"`
ContractAddress common.Address `json:"contract"`
}
EthrDID is a Decentralized Identifier for an Ethereum contract.
func DecodeEthrDID ¶
DecodeEthrDID decodes a Ethr DID string into a DID struct.
func (EthrDID) MarshalText ¶ added in v0.1.1
MarshalText implements encoding.TextMarshaler
func (*EthrDID) UnmarshalText ¶ added in v0.1.1
UnmarshalText implements encoding.TextUnmarshaler
type RawEvent ¶
type RawEvent = CloudEvent[json.RawMessage]
RawEvent is a cloudevent with a json.RawMessage data field. It supports both "data" and "data_base64" (CloudEvents JSON spec).
type StoredEvent ¶ added in v0.2.8
StoredEvent wraps a RawEvent with metadata produced when an event is persisted to backing storage (ClickHouse, Parquet bundles, S3). Use this at the boundary between the in-memory event and the storage layer.
DataIndexKey, when non-empty, is the storage key (e.g. S3 object key) of an external object holding the payload. In that case the embedded RawEvent's Data and DataBase64 fields will typically be empty.
VoidsID, when non-empty, is the id of the attestation that this event tombstones. It is only meaningful for events whose Type is TypeAttestationTombstone and is extracted server-side from the signed Data payload — it must never be set from producer-supplied input directly. It is used to cheaply populate the voids_id column in ClickHouse, but is not stored as a column in Parquet bundles: you would have to parse the data section of a Parquet row to recover the id.
StoredEvent is deliberately separate from CloudEventHeader / RawEvent so that the wire-format types remain pure and shared safely across services — DataIndexKey and VoidsID point into trusted internal storage and must never be set from producer-supplied input.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
clickhouse-container
command
Package main is a binary for creating a test ClickHouse container.
|
Package main is a binary for creating a test ClickHouse container. |
|
migrations
command
|
|