message

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package message provides utilities for representing information about Dogma messages and their use within an application.

Index

Constants

This section is empty.

Variables

Roles is a slice of the valid message roles.

Functions

This section is empty.

Types

type Name

type Name struct {
	// contains filtered or unexported fields
}

Name is the fully-qualified name of a message type.

func NameOf

func NameOf(v dogma.Message) Name

NameOf returns the fully-qualified type name of v.

func (Name) IsZero

func (n Name) IsZero() bool

IsZero returns true if n is the zero-value.

func (Name) MarshalBinary

func (n Name) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the name.

func (Name) MarshalText

func (n Name) MarshalText() ([]byte, error)

MarshalText returns a UTF-8 representation of the name.

func (Name) String

func (n Name) String() string

String returns the fully-qualified type name as a string.

func (*Name) UnmarshalBinary

func (n *Name) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a type from its binary representation.

func (*Name) UnmarshalText

func (n *Name) UnmarshalText(text []byte) error

UnmarshalText unmarshals a name from its UTF-8 representation.

type NameCollection

type NameCollection interface {
	// Has returns true if n is in the container.
	Has(n Name) bool

	// HasM returns true if NameOf(m) is in the container.
	HasM(m dogma.Message) bool

	// Each invokes fn once for each name in the container.
	//
	// Iteration stops when fn returns false or once fn has been invoked for all
	// names in the container.
	//
	// It returns true if fn returned true for all names.
	Each(fn func(Name) bool) bool
}

NameCollection is an interface for containers of message names.

type NameRoles

type NameRoles map[Name]Role

NameRoles is an implementation of NameCollection that maps message types to their roles.

func (NameRoles) Add

func (nr NameRoles) Add(n Name, r Role) bool

Add maps n to r.

It returns true if the mapping was added, or false if the map already contained the name.

func (NameRoles) AddM

func (nr NameRoles) AddM(m dogma.Message, r Role) bool

AddM adds NameOf(m) to nr.

It returns true if the mapping was added, or false if the map already contained the name.

func (NameRoles) Each

func (nr NameRoles) Each(fn func(Name) bool) bool

Each invokes fn once for each name in the container.

Iteration stops when fn returns false or once fn has been invoked for all types in the container.

It returns true if fn returned true for all types.

func (NameRoles) Has

func (nr NameRoles) Has(n Name) bool

Has returns true if nr contains n.

func (NameRoles) HasM

func (nr NameRoles) HasM(m dogma.Message) bool

HasM returns true if nr contains NameOf(m).

func (NameRoles) Remove

func (nr NameRoles) Remove(n Name) bool

Remove removes n from nr.

It returns true if the name was removed, or false if the set did not contain the name.

func (NameRoles) RemoveM

func (nr NameRoles) RemoveM(m dogma.Message) bool

RemoveM removes NameOf(m) from nr.

It returns true if the name was removed, or false if the set did not contain the name.

type NameSet

type NameSet map[Name]struct{}

NameSet is an implementation of NameCollection that contains a distinct set of message names.

func NamesOf

func NamesOf(messages ...dogma.Message) NameSet

NamesOf returns a name set containing the names of the given messages.

func NewNameSet

func NewNameSet(names ...Name) NameSet

NewNameSet returns a NameSet containing the given names.

func (NameSet) Add

func (s NameSet) Add(n Name) bool

Add adds n to s.

It returns true if the name was added, or false if the set already contained the name.

func (NameSet) AddM

func (s NameSet) AddM(m dogma.Message) bool

AddM adds NameOf(m) to s.

It returns true if the name was added, or false if the set already contained the name.

func (NameSet) Each

func (s NameSet) Each(fn func(Name) bool) bool

Each invokes fn once for each name in the container.

Iteration stops when fn returns false or once fn has been invoked for all names in the container.

It returns true if fn returned true for all names.

func (NameSet) Has

func (s NameSet) Has(n Name) bool

Has returns true if s contains n.

func (NameSet) HasM

func (s NameSet) HasM(m dogma.Message) bool

HasM returns true if s contains NameOf(m).

func (NameSet) Remove

func (s NameSet) Remove(n Name) bool

Remove removes n from s.

It returns true if the name was removed, or false if the set did not contain the name.

func (NameSet) RemoveM

func (s NameSet) RemoveM(m dogma.Message) bool

RemoveM removes NameOf(m) from s.

It returns true if the name was removed, or false if the set did not contain the name.

type Role

type Role string

Role is an enumeration of the roles a message can perform within an application.

const (
	// CommandRole is the role for command messages.
	CommandRole Role = "command"

	// EventRole is the role for event messages.
	EventRole Role = "event"

	// TimeoutRole is the role for timeout messages.
	TimeoutRole Role = "timeout"
)

func (Role) Is

func (r Role) Is(roles ...Role) bool

Is returns true if r is one of the given roles.

func (Role) Marker

func (r Role) Marker() string

Marker returns a character that identifies the message role when displaying message types.

func (Role) MarshalBinary

func (r Role) MarshalBinary() ([]byte, error)

MarshalBinary returns a binary representation of the message role.

func (Role) MarshalText

func (r Role) MarshalText() ([]byte, error)

MarshalText returns a UTF-8 representation of the message role.

func (Role) MustBe

func (r Role) MustBe(roles ...Role)

MustBe panics if r is not one of the given roles.

func (Role) MustNotBe

func (r Role) MustNotBe(roles ...Role)

MustNotBe panics if r is one of the given roles.

func (Role) MustValidate

func (r Role) MustValidate()

MustValidate panics if r is not a valid message role.

func (Role) ShortString

func (r Role) ShortString() string

ShortString returns a short (3-character) representation of the handler type.

func (Role) String

func (r Role) String() string

func (*Role) UnmarshalBinary

func (r *Role) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a role from its binary representation.

func (*Role) UnmarshalText

func (r *Role) UnmarshalText(text []byte) error

UnmarshalText unmarshals a role from its UTF-8 representation.

func (Role) Validate

func (r Role) Validate() error

Validate return an error if r is not a valid message role.

type Type

type Type struct {
	// contains filtered or unexported fields
}

Type represents the type of a Dogma message.

func TypeOf

func TypeOf(m dogma.Message) Type

TypeOf returns the message type of m.

func (Type) IsZero

func (t Type) IsZero() bool

IsZero returns true if t is the zero-value.

func (Type) Name

func (t Type) Name() Name

Name returns the fully-qualified name for the Go type.

It panics if t.IsZero() returns true.

func (Type) ReflectType

func (t Type) ReflectType() reflect.Type

ReflectType returns the reflect.Type of the message.

It panics if t.IsZero() returns true.

func (Type) String

func (t Type) String() string

String returns a human-readable name for the type.

The returned name is not necessarily globally-unique.

type TypeCollection

type TypeCollection interface {
	// Has returns true if t is in the container.
	Has(t Type) bool

	// HasM returns true if TypeOf(m) is in the container.
	HasM(m dogma.Message) bool

	// Each invokes fn once for each type in the container.
	//
	// Iteration stops when fn returns false or once fn has been invoked for all
	// types in the container.
	//
	// It returns true if fn returned true for all types.
	Each(fn func(Type) bool) bool
}

TypeCollection is an interface for containers of message types.

type TypeRoles

type TypeRoles map[Type]Role

TypeRoles is an implementation of TypeCollection that maps message types to their roles.

func (TypeRoles) Add

func (tr TypeRoles) Add(t Type, r Role) bool

Add maps t to r.

It returns true if the mapping was added, or false if the map already contained the type.

func (TypeRoles) AddM

func (tr TypeRoles) AddM(m dogma.Message, r Role) bool

AddM adds TypeOf(m) to tr.

It returns true if the mapping was added, or false if the map already contained the type.

func (TypeRoles) Each

func (tr TypeRoles) Each(fn func(Type) bool) bool

Each invokes fn once for each type in the container.

Iteration stops when fn returns false or once fn has been invoked for all types in the container.

It returns true if fn returned true for all types.

func (TypeRoles) Has

func (tr TypeRoles) Has(t Type) bool

Has returns true if tr contains t.

func (TypeRoles) HasM

func (tr TypeRoles) HasM(m dogma.Message) bool

HasM returns true if tr contains TypeOf(m).

func (TypeRoles) Remove

func (tr TypeRoles) Remove(t Type) bool

Remove removes t from tr.

It returns true if the type was removed, or false if the set did not contain the type.

func (TypeRoles) RemoveM

func (tr TypeRoles) RemoveM(m dogma.Message) bool

RemoveM removes TypeOf(m) from tr.

It returns true if the type was removed, or false if the set did not contain the type.

type TypeSet

type TypeSet map[Type]struct{}

TypeSet is an implementation of TypeCollection that contains a distinct set of message types.

func NewTypeSet

func NewTypeSet(types ...Type) TypeSet

NewTypeSet returns a TypeSet containing the given types.

func TypesOf

func TypesOf(messages ...dogma.Message) TypeSet

TypesOf returns a type set containing the types of the given messages.

func (TypeSet) Add

func (s TypeSet) Add(t Type) bool

Add adds t to s.

It returns true if the type was added, or false if the set already contained the type.

func (TypeSet) AddM

func (s TypeSet) AddM(m dogma.Message) bool

AddM adds TypeOf(m) to s.

It returns true if the type was added, or false if the set already contained the type.

func (TypeSet) Each

func (s TypeSet) Each(fn func(Type) bool) bool

Each invokes fn once for each type in the container.

Iteration stops when fn returns false or once fn has been invoked for all types in the container.

It returns true if fn returned true for all types.

func (TypeSet) Has

func (s TypeSet) Has(t Type) bool

Has returns true if s contains t.

func (TypeSet) HasM

func (s TypeSet) HasM(m dogma.Message) bool

HasM returns true if s contains TypeOf(m).

func (TypeSet) Remove

func (s TypeSet) Remove(t Type) bool

Remove removes t from s.

It returns true if the type was removed, or false if the set did not contain the type.

func (TypeSet) RemoveM

func (s TypeSet) RemoveM(m dogma.Message) bool

RemoveM removes TypeOf(m) from s.

It returns true if the type was removed, or false if the set did not contain the type.

Jump to

Keyboard shortcuts

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