💯Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package validator_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gopkg.in/joeybloggs/go-validate-yourself.v0"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserDetails struct {
|
|
|
|
Address string `validate:"required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
FirstName string `validate:"required"`
|
|
|
|
Details *UserDetails
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateStruct(t *testing.T) {
|
|
|
|
|
|
|
|
u := &User{
|
|
|
|
FirstName: "Dean Karn",
|
|
|
|
Details: &UserDetails{
|
|
|
|
"26 Here Blvd.",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
errors := validator.ValidateStruct(u)
|
|
|
|
|
|
|
|
fmt.Println(errors)
|
|
|
|
}
|