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
feat(api): simplify parsing and validation of http input params #3344
feat(api): simplify parsing and validation of http input params #3344
Conversation
0d93a1b
to
02b46de
Compare
fde36e4
to
992ad1c
Compare
pkg/api/welcome_message.go
Outdated
@@ -29,17 +29,19 @@ func (s *Service) getWelcomeMessageHandler(w http.ResponseWriter, r *http.Reques | |||
} | |||
|
|||
func (s *Service) setWelcomeMessageHandler(w http.ResponseWriter, r *http.Request) { | |||
logger := s.logger.WithName("post_wallet").Build() |
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.
copy-paste 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.
Yup, fixed.
@@ -92,8 +92,8 @@ paths: | |||
application/json: |
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 think changes to SwarmDebug.yaml can be avoided as we should not be incrementing versions here when we plan to not support it going ahead.
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.
Added the recommended semver changes to the PR description.
pkg/api/balances.go
Outdated
balances, err := s.accounting.Balances() | ||
if err != nil { | ||
jsonhttp.InternalServerError(w, errCantBalances) | ||
s.logger.Debug("balances: get balances failed", "error", err) | ||
s.logger.Error(nil, "balances: get balances failed") | ||
logger.Debug("balances: get balances failed", "error", err) |
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.
remove "balances" from the msg
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.
Nice catch, done!
pkg/api/util.go
Outdated
} | ||
|
||
// mapStructure maps the input to the output values. | ||
// The input is on of the following: |
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.
one
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.
Done.
@@ -662,12 +752,12 @@ func equalASCIIFold(s, t string) bool { | |||
// direct push to the network (default) a pushStamperPutter is returned. | |||
// returns a function to wait on the errorgroup in case of a pushing stamper putter. | |||
func (s *Service) newStamperPutter(r *http.Request) (storage.Storer, func() error, error) { | |||
batch, err := requestPostageBatchId(r) | |||
batch, err := requestPostageBatchId(r) // TODO: extrapolate the headers parsing to the handler level! |
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.
these TODOs
are meant to be fixed in a future PR?
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, there is an existing issue for that: #3371
2bedbed
to
267e65b
Compare
25ea270
to
1e49a37
Compare
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.
Looks really good!
1e49a37
to
2fd3d46
Compare
2fd3d46
to
4a0b630
Compare
Really nice ! |
func MustParseVerbosityLevel(s string) Level { | ||
l, err := ParseVerbosityLevel(s) | ||
if err != nil { | ||
panic(err) |
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.
please handle error instead of panicing
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.
This is the Must
pattern commonly used in the std lib (e.g. regexp.MustCompile
). It is used in cases where the input has already been validated and simplifies initialization.
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.
Regardless of naming convention, having panic in code may lead to unexpected program termination. It is risky to be certain that some execution flows will not cause program to terminate.
Also, this rule is documented in coding style doc.
7708749
to
dbff8fb
Compare
d5e8513
to
25f9f1c
Compare
25f9f1c
to
f9e5910
Compare
Checklist
Description
Closes #3163 #3165 #3371
Open API Spec Version Changes (if applicable)
Swarm.yaml: minor
SwarmDebug.yaml: minor
SwarmCommon.yaml: minor
This change is