Comments (5)
Hi Max,
It will be great to have this implemented and hope to help with it.
As you suggested, I'm planning to add a middleware validator
as middleware/commandhandler/validator/commandhandler.go
.
- Add a command interface with method
Validate()
type Command interface {
eh.Command
// Validate returns the error when validating the command.
Validate() error
}
- The middleware will simply call the validation, if failed, return with the error
func NewMiddleware() eh.CommandHandlerMiddleware {
return eh.CommandHandlerMiddleware(func(h eh.CommandHandler) eh.CommandHandler {
return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
if c, ok := cmd.(Command); ok {
err := c.Validate()
if err != nil {
return err
}
}
// Immediate command execution.
return h.HandleCommand(ctx, cmd)
})
})
}
How do you feel about that? Any other idea?
from eventhorizon.
A flexible way to do it would be to create a separate CommandHandler
middleware that does only validation.
from eventhorizon.
And also, we found a problem (maybe a separate issue) when a struct with private fields was used in a command.
https://github.com/looplab/eventhorizon/blob/master/command.go#L155-L167
According to existing logic, private fields will be skipped and the struct will also be treated as zero value.
e.g. a custom type from time.Time
type customTime time.Time
If validator can be added to each different command, can we make it an optional check?
It will be quite difficult to make it generic and always suitable for all cases.
from eventhorizon.
The approach for the validator looks good.
As for the other issue, If you want to open a new issue for that it would also be welcome.
from eventhorizon.
Great I will go for this then.
from eventhorizon.
Related Issues (20)
- [Question] Multiple domains HOT 2
- [Command Validation] Allow 0 as valid command value
- [Command validation] allow custom logic for IsZero
- Custom MongoDB Collection name for `events` HOT 1
- What's the difference between gcp eventbus and local eventbus HOT 2
- [eventbus] Support Kafka clustering HOT 8
- Add error check for nil event/command
- More explicit error message when trying to project event to deleted projection HOT 1
- [scheduler] Use a lock to avoid scheduling race
- Slack channel sign-up link in the README.md is no longer active HOT 3
- The Todo MVC example not starting properly
- [eventbus/kafka] event is not retried after error in saga.
- AMQP Event Bus? HOT 1
- DB Mutex of Memory outbox blocks Saga HOT 1
- Switch to OpenTelemetry HOT 5
- Is it going to be maintained? HOT 1
- React / Angular / VanillaJS Examples HOT 1
- Additional configuration options for Kafka event bus HOT 1
- Generic Go 1.18 Support
- Events for an aggregate are read without any specific order HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eventhorizon.