go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.73k stars 224 forks source link

Pre validation filters concept #36

Closed autowp closed 6 years ago

autowp commented 6 years ago

Example situations:

Take a look at zend-inputfilter and zend-filter, zend-validator subpackages

$inputFilterConfig = [
    'amount' => [
        'filters'  => [
            ['name' => 'StringTrim']
        ],
        'validators' => [
            ['name' => 'Digits'],
            [
                'name' => 'Between',
                'options' => [
                    'min' => 1,
                    'max' => 10
                ]
            ]
        ]
    ],
    'email' => [
        'filters'  => [
            ['name' => 'StringTrim'],
            ['name' => 'ToLowerCase'],
        ],
        'validators' => [
            ['name' => 'EmailAddress']
        ]
    ]
];
qiangxue commented 6 years ago

Thanks for the suggestion. I do not have plan to support data filtering in this package, for the reason of separation of concerns. It can be in a separate package.

ssoroka commented 5 years ago

It's also trivial to add your own pre-filtering as part of your Validate method.