Key makes it possible to specify validations for map keys. Example: Attribute("map", MapOf(String, Int), func() { Key(func() { Format(FormatDateTime) // map keys are timestamps }) })
(fn func())
| 259 | // }) |
| 260 | // }) |
| 261 | func Key(fn func()) { |
| 262 | at, ok := eval.Current().(*expr.AttributeExpr) |
| 263 | if !ok { |
| 264 | eval.IncompatibleDSL() |
| 265 | return |
| 266 | } |
| 267 | if m, ok := at.Type.(*expr.Map); ok { |
| 268 | eval.Execute(fn, m.KeyType) |
| 269 | return |
| 270 | } |
| 271 | eval.IncompatibleDSL() |
| 272 | } |
| 273 | |
| 274 | // Elem makes it possible to specify validations for array and map values. |
| 275 | // |