toFormat converts the report into the given format.
(format string)
| 156 | |
| 157 | // toFormat converts the report into the given format. |
| 158 | func (r *Report) toFormat(format string) (data []byte, err error) { |
| 159 | switch format { |
| 160 | case JSON: |
| 161 | data, err = json.Marshal(r) |
| 162 | case YAML: |
| 163 | data, err = yaml.Marshal(r) |
| 164 | case Text: |
| 165 | data, err = generateTextReport(r) |
| 166 | case Summary: |
| 167 | data, err = json.Marshal(r.toSummary()) |
| 168 | default: |
| 169 | return nil, fmt.Errorf("%q is not a valid report format", format) |
| 170 | } |
| 171 | return |
| 172 | } |
| 173 | |
| 174 | // toSummary returns a condensed version of the report. |
| 175 | func (r *Report) toSummary() summary { |