feat(binding): add support for custom validator / validation tags (#1068)
* feat(binding): Add support for custom validation tags * docs: Add example for custom validation tag * test(binding): Add test for registering custom validation
This commit is contained in:
committed by
Javier Provecho Fernandez
parent
030b1aaf72
commit
26c3f42095
@ -4,7 +4,11 @@
|
||||
|
||||
package binding
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
validator "gopkg.in/go-playground/validator.v8"
|
||||
)
|
||||
|
||||
const (
|
||||
MIMEJSON = "application/json"
|
||||
@ -31,6 +35,11 @@ type StructValidator interface {
|
||||
// If the struct is not valid or the validation itself fails, a descriptive error should be returned.
|
||||
// Otherwise nil must be returned.
|
||||
ValidateStruct(interface{}) error
|
||||
|
||||
// RegisterValidation adds a validation Func to a Validate's map of validators denoted by the key
|
||||
// NOTE: if the key already exists, the previous validation function will be replaced.
|
||||
// NOTE: this method is not thread-safe it is intended that these all be registered prior to any validation
|
||||
RegisterValidation(string, validator.Func) error
|
||||
}
|
||||
|
||||
var Validator StructValidator = &defaultValidator{}
|
||||
|
Reference in New Issue
Block a user