-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to validate and update a message using a collection o… #167
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #167 +/- ##
==========================================
+ Coverage 51.40% 52.88% +1.47%
==========================================
Files 31 32 +1
Lines 4739 4894 +155
==========================================
+ Hits 2436 2588 +152
- Misses 2111 2113 +2
- Partials 192 193 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, just 1 note
I saw we're adding validators. I don't see an issue with clients having more than 1 place where wrp validation occurs. But should we consider reusing the wrpvalidation code where we can in order to keep things aligned?
for example, changing func ValidateMessageType() NormifyOption
to
// ValidateMessageType ensures that the message type is valid.
func ValidateMessageType() NormifyOption {
return optionFunc(wrpvalidator.MessageType)
}
normify.go
Outdated
|
||
// Process applies the normalizing and validating options to the message. It | ||
// returns an error if any of the options fail. | ||
func (n *Normify) Process(m *Message) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style suggestion if we wanted to keep things arbitrarily consistent
func (n *Normify) Process(m *Message) error { | |
func (n *Normify) Normify(m *Message) error { |
or leave that along and change func (f optionFunc) normify(m *Message) error
to
func (f optionFunc) process(m *Message) error {
return f(m)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with leaving it as is, but I wanted to point it out in case that was the intention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I was worried this might feel like a stuttering API if I called it Normify
. I'm fine either way. @johnabass what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general convention with a single-method interface is essentially:
type Xer interface {
X()
}
So, in this case:
type Normifier interface {
Normify()
}
The stuttering principal doesn't apply because you don't refer to the method in the same line as the type in normal flow:
var n wrp.Normifier = wrp.NewNormifier(...)
n.Normify() // different line from above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a different note, where validation is taking place in this package should we consider reusing the wrpvalidation code where we can in order to keep things aligned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as much as possible we should use this library for validation. There are some server-specific rules, like what scytale does. But for the most part, all our services should apply the same validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denopink I think we should have wrpvalidation
use this code when possible as wrpvalidation
is quite involved regarding metrics. I decided to punt on variants of these options that support metrics for now as I don't immediately need them nor do I have the cycles to refactor wrpvalidation
to use this yet. My current thinking on the pattern for how to do them is like this:
// EnsureTransactionUUID ensures that the message has a transaction UUID. If
// the message does not have a transaction UUID, a new one is generated and
// added to the message.
func EnsureTransactionUUID(onadded ...func()) NormifierOption {
return optionFunc(func(m *Message) error {
if m.TransactionUUID == "" {
id, err := uuid.NewRandom()
if err != nil {
return err
}
m.TransactionUUID = id.String()
for _, fn := range onadded {
if fn != nil {
fn()
}
}
}
return nil
})
}
…f Options.