(w io.Writer, sectionHeader string, sectionPrefix string, payload []byte, source *FileBodySource, timestamp time.Time)
| 1206 | } |
| 1207 | |
| 1208 | func writeAPISectionWithSource(w io.Writer, sectionHeader string, sectionPrefix string, payload []byte, source *FileBodySource, timestamp time.Time) error { |
| 1209 | if !hasFileBodySourcePayload(source) { |
| 1210 | return writeAPISection(w, sectionHeader, sectionPrefix, payload, timestamp) |
| 1211 | } |
| 1212 | if len(payload) > 0 { |
| 1213 | if errWrite := writeAPISection(w, sectionHeader, sectionPrefix, payload, timestamp); errWrite != nil { |
| 1214 | return errWrite |
| 1215 | } |
| 1216 | } |
| 1217 | if _, errWrite := io.WriteString(w, sectionHeader); errWrite != nil { |
| 1218 | return errWrite |
| 1219 | } |
| 1220 | if !timestamp.IsZero() { |
| 1221 | if _, errWrite := io.WriteString(w, fmt.Sprintf("Timestamp: %s\n", timestamp.Format(time.RFC3339Nano))); errWrite != nil { |
| 1222 | return errWrite |
| 1223 | } |
| 1224 | } |
| 1225 | tracker := &trailingNewlineTrackingWriter{writer: w} |
| 1226 | if errWrite := source.WriteTo(tracker); errWrite != nil { |
| 1227 | return errWrite |
| 1228 | } |
| 1229 | if errWrite := writeSectionSpacing(w, tracker.trailingNewlines); errWrite != nil { |
| 1230 | return errWrite |
| 1231 | } |
| 1232 | return nil |
| 1233 | } |
| 1234 | |
| 1235 | func writePreformattedAPISectionWithSource(w io.Writer, sectionHeader string, sectionPrefix string, payload []byte, source *FileBodySource, timestamp time.Time) error { |
| 1236 | if !hasFileBodySourcePayload(source) { |
no test coverage detected