Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

opencodeco/validgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

How to build ValidGen

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.

Validations

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/TypeStringNumeric typesBooleanSliceArrayMapTimeDuration
eqIWW---WW
eq_ignore_caseI-------
gt-W----WW
gte-W----WW
lt-W----WW
lte-W----WW
neqIWW---WW
neq_ignore_caseI-------
lenI--WWW--
maxI--WWWWW
minI--WWWWW
oneofWWWWWW-W
requiredIWWWWWWW

Steps to run the unit tests

The steps to run the unit tests are:

# Enter in the project root foldercd validgen# Run the unit testsmake unittests

Steps to run the benchmark tests

The steps to run the benchmark tests are:

# Enter in the project root foldercd validgen# Run the benchmark testsmake benchtests

Steps to run the end-to-end tests

The steps to run the end-to-end tests are:

# Enter in the project root foldercd validgen# Run the end-to-end testsmake endtoendtests

Steps to run the examples

All examples are in the_examples folder.

Steps to run test01

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 .

Steps to run test02

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 .

Steps to run test03

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 .

License

ValidGen usesMIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp