Skip to content

Siberia-validation is a library for a simple and convenient validation a passed value It's pretty easy to use and extend if you need a custom validation logic

License

Notifications You must be signed in to change notification settings

siberia-projects/siberia-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Siberia Validation

Author Source Code

What is it?

Siberia-validation is a library for a simple and convenient validation a passed value

It's pretty easy to use and extend if you need a custom validation logic

How to download?

john@doe-pc:~$ go get github.com/siberia-projects/siberia-validation

How to use?

To use it you have to do the following:

  • Create all necessary ConstraintValidator(s)
  • Create a SimpleConstraintValidatorRegistry
  • Put them into the SimpleConstraintValidatorRegistry
  • Create a SimpleValidator with passing the registry
  • Execute a method Validate() with passing a value you want to validate and all needed Constraint(s)

For your convenience the NewSimpleConstraintValidatorRegistryWithDefaultValidators exists

If a value is invalid you will have a ConstraintViolationError which holds every violation error inside itself

Examples

package main

import (
	"github.com/siberia-projects/siberia-validation/pkg/validation"
)

func main() {
	registry := validation.NewSimpleConstraintValidatorRegistryWithDefaultValidators()
	validator := validation.NewSimpleValidator(registry)

	err := validator.Validate("valid_value", []validation.Constraint{
		&validation.NotNil{},
		&validation.NotBlank{},
	})

	if err != nil {
		println(err.Error())
		return
	}

	println("Everything is valid!")
}

About

Siberia-validation is a library for a simple and convenient validation a passed value It's pretty easy to use and extend if you need a custom validation logic

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages