message

package
v0.19.19 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 7 Imported by: 14

Documentation

Overview

Package message provides basic reflection utilities specialized for representing and querying information about Dogma messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Kinds added in v0.16.2

func Kinds() iter.Seq[Kind]

Kinds returns a sequence that yields all valid Kind values.

func MapByKind added in v0.16.1

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

MapByKind 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 MapByKindOf added in v0.16.1

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

MapByKindOf 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 if the function associated with m's kind is nil, or if m does not implement dogma.Command, dogma.Event or dogma.Timeout.

func MapByKindOfWithErr added in v0.16.1

func MapByKindOfWithErr[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)

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

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

It panics if the function associated with m's kind is nil, or if m does not implement dogma.Command, dogma.Event or dogma.Timeout.

func SwitchByKind added in v0.16.1

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

SwitchByKind 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 if the function associated with k is nil, or if k is not a valid Kind.

func SwitchByKindOf added in v0.16.1

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

SwitchByKindOf 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 if the function associated with m's kind is nil, or if m does not implement dogma.Command, dogma.Event or dogma.Timeout.

Types

type Kind added in v0.16.1

type Kind int

Kind is an enumeration of the different kinds of messages.

const (
	// CommandKind is the [Kind] for a "command" message, which is a request to make a
	// single atomic change to the application's state. Command messages
	// implement the [dogma.Command] interface.
	CommandKind Kind = iota

	// EventKind is the [Kind] for an "event" message, which indicates that the
	// application state has changed in some way. Event messages implement the
	// [dogma.Event] interface.
	EventKind

	// TimeoutKind is the [Kind] for a "timeout" message, which is a message
	// that model business logic that depends on the passage of time. Timeout
	// messages implement the [dogma.Timeout] interface.
	TimeoutKind
)

func KindFor added in v0.16.1

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.16.1

func KindOf(m dogma.Message) Kind

KindOf returns the Kind of m.

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

func (Kind) String added in v0.16.1

func (k Kind) String() string

func (Kind) Symbol added in v0.16.1

func (k Kind) Symbol() string

Symbol returns a single-character symbol that represents the kind. It is often appended to a Name to make it easy to distinguish between different kinds of messages.

type Name added in v0.16.1

type Name string

Name is the fully-qualified name of a Go type that implements dogma.Command, dogma.Event or dogma.Timeout.

func NameFor added in v0.16.1

func NameFor[T dogma.Message]() Name

NameFor returns the Name of T.

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

func NameOf added in v0.16.1

func NameOf(m dogma.Message) Name

NameOf returns the fully-qualified type name of m.

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

type Type

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

Type is the representation of a Go type that implements dogma.Command, dogma.Event or dogma.Timeout.

func TypeFor added in v0.16.1

func TypeFor[T dogma.Message]() Type

TypeFor returns the message type for T.

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

func TypeFromReflect added in v0.16.1

func TypeFromReflect(r reflect.Type) Type

TypeFromReflect returns the message type for the Go type represented by r.

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

func TypeOf

func TypeOf(m dogma.Message) Type

TypeOf returns the message type of m.

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

func (Type) Kind added in v0.16.1

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 added in v0.16.1

func (t Type) Name() Name

Name returns the fully-qualified name for the Go type that implements the message.

func (Type) ReflectType

func (t Type) ReflectType() reflect.Type

ReflectType returns the reflect.Type of the message.

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