format

package
v2.16.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 5 Imported by: 30 modules, 32 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package format formats structured events.

The "application/cloudevents+json" format is built-in and always available. Other formats may be added.

Index

Constants

View Source
const Prefix = "application/cloudevents"

Prefix for event-format media types.

Variables

View Source
var JSON = jsonFmt{}

JSON is the built-in "application/cloudevents+json" format.

View Source
var JSONBatch = jsonBatchFmt{}

JSONBatch is the built-in "application/cloudevents-batch+json" format.

Functions

func Add

func Add(f Format)

Add a new Format. It can be retrieved by Lookup(f.MediaType())

func IsFormat

func IsFormat(mediaType string) bool

IsFormat returns true if mediaType begins with "application/cloudevents"

func Marshal

func Marshal(mediaType string, e *event.Event) ([]byte, error)

Marshal an event to bytes using the mediaType event format.

func Unmarshal

func Unmarshal(mediaType string, b []byte, e *event.Event) error

Unmarshal bytes to an event using the mediaType event format.

Types

type Format

type Format interface {
	// MediaType identifies the format
	MediaType() string
	// Marshal event to bytes
	Marshal(*event.Event) ([]byte, error)
	// Unmarshal bytes to event
	Unmarshal([]byte, *event.Event) error
}

Format marshals and unmarshals structured events to bytes.

func Lookup

func Lookup(contentType string) Format

Lookup returns the format for contentType, or nil if not found.

Jump to

Keyboard shortcuts

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