Skip to content

Skipping Validatable interface #192

@rmscoal

Description

@rmscoal

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions