title: How can I validate a struct datatype with a custom validator?
body: <p>I am using <code>go-playground/validator/v10</code> to validate some input and have some trouble with custom validation tags and functions. The problem is that the function is not called when one of the struct fields is a different struct. This is an example:</p>
  <pre><code>type ChildStruct struct {
      Value int
  }
  
  type ParentStruct struct {
      Child ChildStruct `validate:&quot;myValidate&quot;`
  }
  
  func myValidate(fl validator.FieldLevel) bool {
      fmt.Println(&quot;INSIDE MY VALIDATOR&quot;) // &lt;- This is never printed
      return false
  }
  
  func main() {
      validator := validator.New()
      validator.RegisterValidation(&quot;myValidate&quot;, myValidate)
      data := &amp;ParentStruct{
          Child: ChildStruct{
              Value: 10,
          },
      }
      validateErr := validator.Struct(data)
      if validateErr != nil { // &lt;- This is always nil since MyValidate is never called
          fmt.Println(&quot;GOT ERROR&quot;)
          fmt.Println(validateErr)
      }
      fmt.Println(&quot;DONE&quot;)
  }
  </code></pre>
  <p>If I change the parentStruct to:</p>
  <pre><code>type ParentStruct struct {
      Child int `validate:&quot;myValidate&quot;`
  }
  </code></pre>
  <p>everything works.
  If I add the <code>validate:&quot;myValidate&quot;</code> part to the ChildStruct it is also working, however, then the error that is returned is saying that the ChildStruct.Value is wrong when it should say that the ParentStruct.Child is wrong.</p>
  <p>Anyone know what I am doing wrong?</p>