Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping Validatable interface #192

Open
rmscoal opened this issue Feb 17, 2024 · 0 comments
Open

Skipping Validatable interface #192

rmscoal opened this issue Feb 17, 2024 · 0 comments

Comments

@rmscoal
Copy link

rmscoal commented Feb 17, 2024

I wanted to validate a struct. For example:

type User struct {
    Name string
    Cars []Car
}

type Car struct {
    ID int
    Name string
}

func (v User) Validate() error {
    return validation.ValidateStruct(&v,
        validation.Field(&v.Name, validation.Required),
        validation.Field(&v.Cars, validation.Length(1, 0)), // car's validation is triggered here... But I don't really care... How can I skip it
    )
}

func (c Car) Validate() error {
    return validation.ValidateStruct(&c,
        validation.Field(&c.Name, validation.Required),
    )
}

As of the documentation, Car struct implements the Validatable interface. Hence, it will be .Validate() will be called. But what if I want to skip it? Just the validation.Length().

Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant