format

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: Apache-2.0 Imports: 4 Imported by: 31

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.

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