Skip to content

Commit

Permalink
updated upgrade instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Jan 31, 2020
1 parent f8d2e47 commit e952662
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Upgrade Instructions

## Upgrade from 3.x to 4.x
* Change your error message placeholders from the Go `fmt` package `verbs` to the `template variables`.

If you are customizing the error messages of the following built-in validation rules, you may need to
change the parameter placeholders from `%v` to the Go template variable placeholders.
* `Length`: use `{{.min}}` and `{{.max}}` in the error message to refer to the minimum and maximum lengths.
* `Min`: use `{{.threshold}}` in the error message to refer to the lower bound.
* `Max`: use `{{.threshold}}` in the error message to refer to the upper bound
* `MultipleOf`: use `{{.base}}` in the error message to refer to the base of the multiples.

For example,
```go
// 3.x
// Assume you want to set a custom message for the LengthRule:
var lengthRule= validation.Length(2,10).Error("the length must be between %v and %v")
lengthRule := validation.Length(2,10).Error("the length must be between %v and %v")

// 4.x
var lengthRule= validation.Length(2,10).Error("the length must be between {{.min}} and {{.max}}")
lengthRule := validation.Length(2,10).Error("the length must be between {{.min}} and {{.max}}")
```

## Upgrade from 2.x to 3.x
Expand Down

0 comments on commit e952662

Please sign in to comment.