Skip to content

Commit

Permalink
Slice level checkers documented. (#155)
Browse files Browse the repository at this point in the history
# Describe Request

Slice level checkers documented.

# Change Type

Documentation improvement.
  • Loading branch information
cinar authored Dec 29, 2024
1 parent e119e84 commit 2c3a57b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ if !valid {

In this example, the `is-fruit` checker is used to validate that the `Name` field of the `Item` struct is either "apple" or "banana".

# Slice and Item Level Checkers

When adding checker struct tags to a slice, you can use the `@` prefix to indicate that the checker should be applied to the slice itself. Checkers without the `@` prefix will be applied to the individual items within the slice. Here is an example:

```golang
type Person struct {
Name string `checkers:"required"`
Emails []string `checkers:"@max-len:1 max-len:4"`
}
```

In this example:
- `@max-len:1` ensures that the `Emails` slice itself has at most one item.
- `max-len:4` ensures that each email string within the `Emails` slice has a maximum length of 4 characters.

# Localized Error Messages

When validation fails, Checker returns an error. By default, the [Error()](DOC.md#CheckError.Error) function provides a human-readable error message in `en-US` locale.
Expand Down

0 comments on commit 2c3a57b

Please sign in to comment.