format

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

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 ce.Event) ([]byte, error)

Marshal an event to bytes using the mediaType event format.

func Unmarshal

func Unmarshal(mediaType string, b []byte, e *ce.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(ce.Event) ([]byte, error)
	// Unmarshal bytes to event
	Unmarshal([]byte, *ce.Event) error
}

Format marshals and unmarshals structured events to bytes.

func Lookup

func Lookup(mediaType string) Format

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

type UnknownFormat added in v1.0.0

type UnknownFormat string

UnknownFormat allows an event with an unknown format string to be forwarded, but Marshal() and Unmarshal will always fail.

func (UnknownFormat) Marshal added in v1.0.0

func (uf UnknownFormat) Marshal(ce.Event) ([]byte, error)

func (UnknownFormat) MediaType added in v1.0.0

func (uf UnknownFormat) MediaType() string

func (UnknownFormat) Unmarshal added in v1.0.0

func (uf UnknownFormat) Unmarshal([]byte, *ce.Event) error

Jump to

Keyboard shortcuts

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