goweb/cqrs/match.go

34 lines
632 B
Go
Raw 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 {
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
}
}