You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, @bupd, I'm interested in this issue and have two ideas to solve the input problem.
I'm not sure which one is better.
The first one is:
The second one is:
And I'm not clear about the rules for trimming the string of input, do I need to trim only the leading of spaces, only the trailing of spaces, both the leading and trailing of spaces? Or are there other rules?
I'd really appreciate any additional helpful ideas you have to share!
Hello @JianMinTang, thanks for your interest in addressing this issue.
And I'm not clear about the rules for trimming the string of input, do I need to trim only the leading of spaces, only the trailing of spaces, both the leading and trailing of spaces? Or are there other rules?
Regarding your question on trimming the input string:
The Go method strings.TrimSpace will indeed trim both leading and trailing whitespaces. This should work well for cleaning up the input.
Here's my suggested approach to handle this across all user input fields:
Step 1: Use strings.TrimSpace to remove both leading and trailing spaces from the input.
Step 2: Check if the resulting string is empty, and if so, return an appropriate error.
Additional Step: You can also apply more formatting rules & appropriate error messages as needed for specific fields to ensure the input adheres to the expected API resource model.
For reference, please take a look at the implementation in this PR review. You can replicate the pattern used there for all relevant input fields. That's exactly the kind of input validation we need to implement throughout.
Feel free to share any further thoughts or ideas you might have!
Expected Outcome
You can make use of Validation method mentioned here.
The text was updated successfully, but these errors were encountered: