- Notifications
You must be signed in to change notification settings - Fork0
License
opencodeco/validgen
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Validator is an amazing project. But in applications with high frequency use, the way that validator works (i.e. reflection) can cause performance penalty.
ValidGen born to solve that gap. Instead of use reflection, ValidGen uses the code generating approach.
This project aims to be compatible with validator tag syntax.
At this time it is an unstable project and should not be used in production environments.
The following requirements are needed to build the project:
- Git
- Go >= 1.24
- Make
The steps to build are:
# Clone the project repositorygit clone git@github.com:opencodeco/validgen.git# Enter in the project root foldercd validgen# Build the binarymake build
After that the executable will be inbin/validgen
.
The following validations will be implemented:
- eq (equal): must be equal to the specified value
- eq_ignore_case (equal ignoring case): must be equal to the specified value (ignoring case)
- gt (greater than): must be > to the specified value
- gte (greater than or equal): must be >= to the specified value
- lt (less than): must be < to the specified value
- lte (less than or equal): must be <= to the specified value
- neq (not equal): must not be equal to the specified value
- neq_ignore_case (not equal ignoring case): must not be equal to the specified value (ignoring case)
- len (length): must have the following length
- max (max): must have no more than max characters
- min (min): must have no less than min characters
- oneof (one of): must be one of the following values
- required (required): is required
The following table shows the validations and possible types, where "I" means "Implemented", "W" means "Will be implemented" and "-" means "Will not be implemented":
Validation/Type | String | Numeric types | Boolean | Slice | Array | Map | Time | Duration |
---|---|---|---|---|---|---|---|---|
eq | I | W | W | - | - | - | W | W |
eq_ignore_case | I | - | - | - | - | - | - | - |
gt | - | W | - | - | - | - | W | W |
gte | - | W | - | - | - | - | W | W |
lt | - | W | - | - | - | - | W | W |
lte | - | W | - | - | - | - | W | W |
neq | I | W | W | - | - | - | W | W |
neq_ignore_case | I | - | - | - | - | - | - | - |
len | I | - | - | W | W | W | - | - |
max | I | - | - | W | W | W | W | W |
min | I | - | - | W | W | W | W | W |
oneof | W | W | W | W | W | W | - | W |
required | I | W | W | W | W | W | W | W |
The steps to run the unit tests are:
# Enter in the project root foldercd validgen# Run the unit testsmake unittests
The steps to run the benchmark tests are:
# Enter in the project root foldercd validgen# Run the benchmark testsmake benchtests
The steps to run the end-to-end tests are:
# Enter in the project root foldercd validgen# Run the end-to-end testsmake endtoendtests
All examples are in the_examples
folder.
Test01 aims to be a case where all the files are in the same package (in this case, the main package).
# Runs validgen to generate structs validator code./bin/validgen _examples/test01
After that the fileuser_validator.go
will be generated. This file contains UserValidate function that is responsible to check if User object has a valid content.
# Execute the testcd _examples/test01go run .
Test02 aims to be an example where the structs to be validated are in another package (structsinpkg in this test).
# Runs validgen to generate structs validator code./bin/validgen _examples/test02
After that the fileuser_validator.go
will be generated. This file contains UserValidate function that is responsible to check if User object has a valid content.
# Execute the testcd _examples/test02go run .
Test03 aims to be an example where the structs to be validated use min and max tags.
# Runs validgen to generate structs validator code./bin/validgen _examples/test03
After that the fileuser_validator.go
will be generated. This file contains UserValidate function that is responsible to check if User object has a valid content.
# Execute the testcd _examples/test03go run .
ValidGen usesMIT License.
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.