1 // Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2 // Use of this source code is governed by a MIT style
3 // license that can be found in the LICENSE file.
11 "gopkg.in/go-playground/validator.v8"
14 type defaultValidator struct {
16 validate *validator.Validate
19 var _ StructValidator = &defaultValidator{}
21 // ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.
22 func (v *defaultValidator) ValidateStruct(obj interface{}) error {
23 value := reflect.ValueOf(obj)
24 valueType := value.Kind()
25 if valueType == reflect.Ptr {
26 valueType = value.Elem().Kind()
28 if valueType == reflect.Struct {
30 if err := v.validate.Struct(obj); err != nil {
37 // Engine returns the underlying validator engine which powers the default
38 // Validator instance. This is useful if you want to register custom validations
39 // or struct level validations. See validator GoDoc for more info -
40 // https://godoc.org/gopkg.in/go-playground/validator.v8
41 func (v *defaultValidator) Engine() interface{} {
46 func (v *defaultValidator) lazyinit() {
48 config := &validator.Config{TagName: "binding"}
49 v.validate = validator.New(config)