Skip to content

envelope

gitlab.com/phpboyscout/go/envelope is the event every service handles, and the seam each wire format implements to write it and read it back.

type Format interface {
    Encode(Event) (Wire, error)
    Recognises(w Wire) bool
    Decode(Wire) (Event, Foreign, error)
}

func Read(w Wire, formats ...Format) (Event, Foreign, Format, error)
func Validate(e Event) error

An Event is CloudEvents' attribute set: id, source, specversion and type, four optional attributes, extensions, and a payload. A Format turns one into a Wire, the content type, headers and body a transport carries, and back. Each format is a module of its own beside this one:

Module Writes
go/envelope-cloudevents CloudEvents binary mode (the default) and structured mode
go/envelope-masstransit MassTransit's envelope (not yet released)
go/envelope-nservicebus NServiceBus's headers (not yet released)

Read asks every format it is given and decodes with the one that claims the message, so a reader can take several formats while writers move between them. A message no format claims, or that two claim, is refused rather than guessed at.

CloudEvents

URN identifiers such as urn:phpboyscout:schema:orders.created:3 are documented with go/urn.

This module, with its formats, replaces gitlab.com/phpboyscout/go/cloudevents. The design is go/messaging's spec 0014.