StringLength accepts any string and returns a message if the length is not in the given range.
(min, max int)
| 51 | |
| 52 | // StringLength accepts any string and returns a message if the length is not in the given range. |
| 53 | func StringLength(min, max int) func(s string) string { |
| 54 | return func(s string) string { |
| 55 | n := len(s) |
| 56 | |
| 57 | if min == max { |
| 58 | if n != min { |
| 59 | return fmt.Sprintf("must be %d characters", min) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if n < min || n > max { |
| 64 | return fmt.Sprintf("must be between %d and %d characters", min, max) |
| 65 | } |
| 66 | |
| 67 | return "" |
| 68 | } |
| 69 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…