Download this file
| 1 | package fixture |
| 2 | |
| 3 | // Not compiled. A field is a sentence only if every write to a field of that |
| 4 | // name is. The anonymous struct writes an error's text, positionally and by key. |
| 5 | |
| 6 | type Check struct{ Reason string } |
| 7 | |
| 8 | func good() Check { return Check{Reason: "this box has no secrets key"} } |
| 9 | |
| 10 | func positional(w int, err error) { |
| 11 | box := struct{ Reason string }{err.Error()} |
| 12 | jsonError(w, 400, box.Reason) |
| 13 | } |
| 14 | |
| 15 | func keyed(w int, err error) { |
| 16 | box := struct{ Reason string }{Reason: err.Error()} |
| 17 | jsonError(w, 400, box.Reason) |
| 18 | } |
| 19 | |
| 20 | func assigned(w int, err error, c Check) { |
| 21 | c.Reason = err.Error() |
| 22 | jsonError(w, 400, c.Reason) |
| 23 | } |
| 24 | |