MarshalJSON serializes the union per spec §5.2.
()
| 105 | |
| 106 | // MarshalJSON serializes the union per spec §5.2. |
| 107 | func (e ExitCode) MarshalJSON() ([]byte, error) { |
| 108 | hasRich := e.When != "" || e.Recovery != "" || e.MessageTemplate != "" |
| 109 | if e.Description != "" && !hasRich { |
| 110 | return json.Marshal(e.Description) |
| 111 | } |
| 112 | type rich struct { |
| 113 | When string `json:"when,omitempty"` |
| 114 | Recovery string `json:"recovery,omitempty"` |
| 115 | MessageTemplate string `json:"message_template,omitempty"` |
| 116 | } |
| 117 | return json.Marshal(rich{ |
| 118 | When: e.When, |
| 119 | Recovery: e.Recovery, |
| 120 | MessageTemplate: e.MessageTemplate, |
| 121 | }) |
| 122 | } |
| 123 | |
| 124 | // Example is a canonical invocation. Same source feeds both --format json |
| 125 | // and --format md (spec §6); MD rendering wraps cmd in a fenced bash block |
nothing calls this directly
no outgoing calls
no test coverage detected