Skip to content

v0.2.0

Latest
Compare
Choose a tag to compare
@josestg josestg released this 30 Jun 13:48
· 2 commits to main since this release
84da936

Add String Variant Validator

This feature basically provides a simple StringValidator for string variants (~string). In the current latest version, if we need a validator for the type VariantExample string, which is a string variant, we have to convert VariantExample to a string in order to use the StringValidator. These changes add a new API that reuses the StringValidator rules for string variants without any conversion.

Before:

type Variant string

const (
   VariantA Variant = "A"
   VariantB Variant = "B"
)

var validator = goval.String().In(string(VariantA), string(VariantB))

After:

type Variant string

const (
   VariantA Variant = "A"
   VariantB Variant = "B"
)

var validator = goval.StringVariant[Variant]().In(VariantA, VariantB)