34 lines
632 B
Go
34 lines
632 B
Go
|
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 {
|
||
|
return false, ErrInvalidRequestType
|
||
|
}
|
||
|
|
||
|
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 {
|
||
|
return false, ErrInvalidRequestType
|
||
|
}
|
||
|
|
||
|
return reflect.TypeOf(cmd.Request()) == reqType, nil
|
||
|
}
|
||
|
}
|