WriteCapture writes the event stream to the capture file.
(args []string)
| 273 | |
| 274 | // WriteCapture writes the event stream to the capture file. |
| 275 | func (f *App) WriteCapture(args []string) error { |
| 276 | if f.evs == nil { |
| 277 | panic("event source is nil") |
| 278 | } |
| 279 | |
| 280 | if !f.isSingleInstance() { |
| 281 | return ErrAlreadyRunning |
| 282 | } |
| 283 | |
| 284 | fltr, err := filter.NewFromCLI(args, f.config) |
| 285 | if err != nil { |
| 286 | return err |
| 287 | } |
| 288 | if fltr != nil { |
| 289 | f.evs.SetFilter(fltr) |
| 290 | } |
| 291 | err = f.evs.Open(f.config) |
| 292 | if err != nil { |
| 293 | return err |
| 294 | } |
| 295 | f.writer, err = cap.NewWriter(f.config.CapFile, f.psnap, f.hsnap) |
| 296 | if err != nil { |
| 297 | return err |
| 298 | } |
| 299 | errsChan := f.writer.Write(f.evs.Events(), f.evs.Errors()) |
| 300 | go func() { |
| 301 | for err := range errsChan { |
| 302 | log.Warnf("fail to write event to capture: %v", err) |
| 303 | } |
| 304 | }() |
| 305 | return api.StartServer(f.config) |
| 306 | } |
| 307 | |
| 308 | // ReadCapture reconstructs the event stream from the capture file. |
| 309 | func (f *App) ReadCapture(ctx context.Context, args []string) error { |
no test coverage detected