Skip to content

apply validation rules to each item in a Slice #3

@woodsaj

Description

@woodsaj

I would like to be able to apply validation rules to each item in a slice.

eg

type MyStruct struct {
   Id int
   MyNumbers []int `json:"my_numbers" binding:"range(1, 10)"`
}

The following should then fail validation as one of the items in the list is outside of the range.

{
  "id": 1,
  "my_numbers": [1,2,3,4,100]
}

This would require replacing MinSize and MaxSize from being applied to slice lengths, so that rules can instead be used for length of each item in a slice of strings. New rules specific to slice length would then need to be introduced.

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