Documentation
¶
Overview ¶
Package message provides basic reflection utilities specialized for representing and querying information about Dogma messages.
Index ¶
- func Kinds() iter.Seq[Kind]
- func MapByKind[T any](k Kind, command, event, timeout T) T
- func MapByKindOf[T any](m dogma.Message, command func(dogma.Command) T, event func(dogma.Event) T, ...) (result T)
- func MapByKindOfWithErr[T any](m dogma.Message, command func(dogma.Command) (T, error), ...) (result T, err error)
- func SwitchByKind(k Kind, command func(), event func(), timeout func())
- func SwitchByKindOf(m dogma.Message, command func(dogma.Command), event func(dogma.Event), ...)
- type Kind
- type Name
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapByKind ¶ added in v0.16.1
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
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
KindOf returns the Kind of m.
It panics if m does not implement dogma.Command, dogma.Event or dogma.Timeout.
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
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
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
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
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 ¶
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
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
Name returns the fully-qualified name for the Go type that implements the message.
func (Type) ReflectType ¶
ReflectType returns the reflect.Type of the message.