message

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

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

Deprecated: Use github.com/dogmatiq/enginekit/message instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map added in v0.15.0

func Map[T any](
	m dogma.Message,
	command func(dogma.Command) T,
	event func(dogma.Event) T,
	timeout func(dogma.Timeout) T,
) (result T)

Map invokes one of the provided functions based on the Kind of m, and returns the result.

It provides a compile-time guarantee that all kinds are handled, even if new Kind values are added in the future.

It panics with a meaningful message if the function associated with m's kind is nil.

It panics if m does not implement dogma.Command, dogma.Event or dogma.Timeout.

func MapKind added in v0.15.0

func MapKind[T any](k Kind, command, event, timeout T) (result T)

MapKind maps k to a value of type T.

It provides a compile-time guarantee that all possible values are handled, even if new Kind values are added in the future.

It panics if k is not a valid Kind.

func Switch added in v0.15.0

func Switch(
	m dogma.Message,
	command func(dogma.Command),
	event func(dogma.Event),
	timeout func(dogma.Timeout),
)

Switch invokes one of the provided functions based on the Kind of m.

It provides a compile-time guarantee that all kinds are handled, even if new Kind values are added in the future.

It panics with a meaningful message if the function associated with m's kind is nil.

It panics if m does not implement dogma.Command, dogma.Event or dogma.Timeout.

func SwitchKind added in v0.15.0

func SwitchKind(
	k Kind,
	command func(),
	event func(),
	timeout func(),
)

SwitchKind invokes one of the provided functions based on k.

It provides a compile-time guarantee that all possible values are handled, even if new Kind values are added in the future.

It panics with a meaningful message if the function associated with k.

It panics if k is not a valid Kind.

func TryMap added in v0.15.0

func TryMap[T any](
	m dogma.Message,
	command func(dogma.Command) (T, error),
	event func(dogma.Event) (T, error),
	timeout func(dogma.Timeout) (T, error),
) (result T, err error)

TryMap invokes one of the provided functions based on the Kind of m, and returns the result and error.

It provides a compile-time guarantee that all kinds are handled, even if new Kind values are added in the future.

It panics with a meaningful message if the function associated with m's kind is nil.

It panics if m does not implement dogma.Command, dogma.Event or dogma.Timeout.

Types

type Kind added in v0.15.0

type Kind int

Kind is an enumeration of the different kinds of messages.

It is similar to a [Role], however it is not tied to a specific application.

const (
	// CommandKind is a [dogma.Message] that also implements [dogma.Command].
	CommandKind Kind = iota

	// EventKind is a [dogma.Message] that also implements [dogma.Event].
	EventKind

	// TimeoutKind is a [dogma.Message] that also implements [dogma.Timeout].
	TimeoutKind
)

func KindFor added in v0.15.0

func KindFor[T dogma.Message]() Kind

KindFor returns the Kind of the message with type T.

It panics if T does not implement dogma.Command, dogma.Event or dogma.Timeout.

func KindOf added in v0.15.0

func KindOf(m dogma.Message) Kind

KindOf returns the Kind of m.

func (Kind) String added in v0.15.0

func (k Kind) String() string

func (Kind) Symbol added in v0.15.0

func (k Kind) Symbol() string

Symbol returns a character that identifies the message kind when displaying message types.

type Name

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

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

func NameFor added in v0.13.7

func NameFor[T dogma.Message]() Name

NameFor returns the message name for T.

func NameFromStaticType added in v0.15.0

func NameFromStaticType(t types.Type) Name

NameFromStaticType returns the fully-qualified type name of t.

func NameOf

func NameOf(m 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 Type

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

Type represents the type of a Dogma message.

func TypeFor added in v0.13.4

func TypeFor[T dogma.Message]() Type

TypeFor returns the message type for T.

func TypeFromReflect added in v0.4.1

func TypeFromReflect(rt reflect.Type) Type

TypeFromReflect returns the message type of the given reflect type.

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) Kind added in v0.15.0

func (t Type) Kind() Kind

Kind returns the kind of the message represented by t.

It panics of t does not implement dogma.Command, dogma.Event or dogma.Timeout.

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.

Jump to

Keyboard shortcuts

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