goweb/cqrs/match.go

34 lines
630 B
Go
Raw Permalink Normal View History

2020-04-16 16:32:02 +02:00
package cqrs
import (
"reflect"
)
type MatchFunc func(interface{}) (bool, error)
func MatchCommandRequest(req interface{}) MatchFunc {
reqType := reflect.TypeOf(req)
return func(raw interface{}) (bool, error) {
cmd, ok := raw.(Command)
if !ok {
2020-07-07 08:19:15 +02:00
return false, ErrUnexpectedRequest
2020-04-16 16:32:02 +02:00
}
return reflect.TypeOf(cmd.Request()) == reqType, nil
}
}
func MatchQueryRequest(req interface{}) MatchFunc {
reqType := reflect.TypeOf(req)
return func(raw interface{}) (bool, error) {
cmd, ok := raw.(Query)
if !ok {
2020-07-07 08:19:15 +02:00
return false, ErrUnexpectedRequest
2020-04-16 16:32:02 +02:00
}
return reflect.TypeOf(cmd.Request()) == reqType, nil
}
}