-
Notifications
You must be signed in to change notification settings - Fork 13
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
added WRP validator middleware functionality #306
Conversation
Codecov Report
@@ Coverage Diff @@
## main #306 +/- ##
==========================================
- Coverage 21.61% 20.93% -0.68%
==========================================
Files 7 7
Lines 708 731 +23
==========================================
Hits 153 153
- Misses 553 576 +23
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
some suggestions, otherwise looks great!
primaryHandler.go
Outdated
err := v.Validate(*msg) | ||
if err != nil { | ||
w.WriteHeader(http.StatusBadRequest) | ||
fmt.Fprintf( |
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.
u probably forgot to remove this print statement
primaryHandler.go
Outdated
for _, v := range validators { | ||
err := v.Validate(*msg) | ||
if err != nil { | ||
w.WriteHeader(http.StatusBadRequest) |
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.
we can also use http.Error()
something like this maybe
if err != nil {
bodyMsg := fmt.Sprintf(`{"code": %d, "message": "%s"}`,
http.StatusBadRequest,
fmt.Sprintf("failed to validate wrp message: %s", err))
http.Error(w, bodyMsg, http.StatusBadRequest)
return
}
ctx := r.Context() | ||
if msg, ok := wrpcontext.Get[*wrp.Message](ctx); ok { |
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.
ctx := r.Context() | |
if msg, ok := wrpcontext.Get[*wrp.Message](ctx); ok { | |
if msg, ok := wrpcontext.Get[*wrp.Message](r.Context()); ok { |
} | ||
delegate.ServeHTTP(w, r) |
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.
} | |
delegate.ServeHTTP(w, r) | |
} | |
delegate.ServeHTTP(w, r) |
What's Included:
Scytale using the standard WRP validators (SpecValidators which validates the message type, the source and destination, and that message is UTF8) from wrp-go. Validators were created in this PR