Skip to content

Conversation

@xvello
Copy link
Contributor

@xvello xvello commented Jul 28, 2021

Add boolean baked-in validator

Due to technical limitations upstream, some of our structs can only have string fields, but some of these fields will be parsed into booleans by the business logic, using strconv.ParseBool:

ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error.

Similar to the numeric validator, this PR adds a boolean validator that checks that the field will be safely convertible to a boolean. Instead of enumerating all values currently accepted by ParseBool, this PR just calls the method and confirms it does not return an error. The rationale for this is to stay in sync if the accepted values change in future versions of go.

I updated the tests and documentation, but I might have forgotten something else to update.

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 75.1% when pulling 5ce08ba on xvello:feature/boolean into 14221d0 on go-playground:master.

@deankarn deankarn merged commit a67baa7 into go-playground:master Aug 8, 2021
@xvello xvello deleted the feature/boolean branch August 9, 2021 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants