-
Notifications
You must be signed in to change notification settings - Fork 13
Float64 AtLeast
, AtMost
and Between
validators
#18
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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
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.
Very exciting! Thank you for starting this. Some meta feedback first. 😄 Please reach out with any questions.
@bflad Any thoughts on |
I'd suggest adding the word "Attribute" to the summary and capitalizing Value, e.g. package validatordiag
func AttributeValueDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
return diag.NewAttributeErrorDiagnostic(
path,
"Invalid Attribute Value",
capitalize(description) + ", got: " + value,
)
}
// capitalize will uppercase the first letter in a UTF-8 string.
func capitalize(str string) string {
if str == "" {
return ""
}
firstRune, size := utf8.DecodeRuneInString(str)
return string(unicode.ToUpper(firstRune)) + str[size:]
} With callers: response.Diagnostics.Append(validatordiag.AttributeValueDiagnostic(
request.AttributePath,
validator.Description(ctx),
fmt.Sprintf("%f", f),
)) |
All review comments addressed. |
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.
@bflad Are we OK with these Float validators working for both Float64 and Number?
At first I was thinking it might be best if it was strictly just types.Float64
, however we could validate Number as long as it can be represented with big.Exact
accuracy from (*big.Float).Float64()
. That said, I think it is okay if we simplify it only work with Float64 for now, since Number can have up to 512 bits and should likely require specialized validation via the math/big
package anyways.
Co-authored-by: Brian Flad <[email protected]>
Co-authored-by: Brian Flad <[email protected]>
Co-authored-by: Brian Flad <[email protected]>
This reverts commit 1f1f3c0.
Now disallowing |
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.
Awesome!!! This is looking fantastic. Do you mind making a go-changelog entry? e.g. .changelog/18.txt
```release-note:feature
Introduced `float64validator` package with `AtLeast()`, `AtMost()`, and `Between()` validation functions
```
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes #1.
Copied wholesale from https://github.com/hashicorp/terraform-provider-awscc/tree/main/internal/validate.