data_protocol

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataContentTypeJson = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudEvent

type CloudEvent struct {
	SpecVersion     string `json:"specversion"`
	ID              string `json:"id"`
	Type            string `json:"type"`
	Source          string `json:"source"`
	DataContentType string `json:"datacontenttype"`
	Time            string `json:"time"`
	Data            []byte `json:"data"`
}

func NewCloudEvent

func NewCloudEvent(eventID string, eventType string, source string, dataContentType string, data []byte) *CloudEvent

NewCloudEvent 创建CloudEvent 参数: - eventID: 事件ID - eventType: 事件类型 - source: 事件源,如foo.com - dataContentType: 事件数据类型,可以是任何mime类型,如application/json,application/text - data: 要发送的数据 返回值: - CloudEvent

func NewCloudEventJson

func NewCloudEventJson(eventID string, eventType string, source string, obj any) (*CloudEvent, error)

NewCloudEventJson 创建数据是Json类型的CloudEvent 参数: - eventID: 事件ID - eventType: 事件类型 - source: 事件源,如foo.com - obj: 需要转为json的对象 返回值: - CloudEvent - 错误

func UnmarshalJsonCloudEvent

func UnmarshalJsonCloudEvent(cloudEventJsonBytes []byte) (*CloudEvent, error)

UnmarshalJsonCloudEvent Unmarshal格式为Json的CloudEvent 参数: - cloudEventJsonBytes: CloudEvent的Json字节 返回值: - CloudEvent - 错误

func (*CloudEvent) MarshalJson

func (event *CloudEvent) MarshalJson() ([]byte, error)

MarshalJson Marshal格式为Json的CloudEvent 参数: 无 返回值: - CloudEvent的Json字节 - 错误

Jump to

Keyboard shortcuts

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