(w io.Writer, sectionHeader string, sectionPrefix string, payload []byte, timestamp time.Time)
| 1177 | } |
| 1178 | |
| 1179 | func writeAPISection(w io.Writer, sectionHeader string, sectionPrefix string, payload []byte, timestamp time.Time) error { |
| 1180 | if len(payload) == 0 { |
| 1181 | return nil |
| 1182 | } |
| 1183 | |
| 1184 | if bytes.HasPrefix(payload, []byte(sectionPrefix)) { |
| 1185 | if _, errWrite := w.Write(payload); errWrite != nil { |
| 1186 | return errWrite |
| 1187 | } |
| 1188 | } else { |
| 1189 | if _, errWrite := io.WriteString(w, sectionHeader); errWrite != nil { |
| 1190 | return errWrite |
| 1191 | } |
| 1192 | if !timestamp.IsZero() { |
| 1193 | if _, errWrite := io.WriteString(w, fmt.Sprintf("Timestamp: %s\n", timestamp.Format(time.RFC3339Nano))); errWrite != nil { |
| 1194 | return errWrite |
| 1195 | } |
| 1196 | } |
| 1197 | if _, errWrite := w.Write(payload); errWrite != nil { |
| 1198 | return errWrite |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | if errWrite := writeSectionSpacing(w, countTrailingNewlinesBytes(payload)); errWrite != nil { |
| 1203 | return errWrite |
| 1204 | } |
| 1205 | return nil |
| 1206 | } |
| 1207 | |
| 1208 | func writeAPISectionWithSource(w io.Writer, sectionHeader string, sectionPrefix string, payload []byte, source *FileBodySource, timestamp time.Time) error { |
| 1209 | if !hasFileBodySourcePayload(source) { |
no test coverage detected