// report validates the report arguments, sets up the required resources // and writes the report func report(reporter, input, output string) error { var rep vegeta.Reporter switch reporter { case "text": rep = vegeta.ReportText case "json": rep = vegeta.ReportJSON case "plot": rep = vegeta.ReportPlot default: log.Println("Reporter provided is not supported. Using text") rep = vegeta.ReportText } all := vegeta.Results{} for _, input := range strings.Split(input, ",") { in, err := file(input, false) if err != nil { return err } defer in.Close() results := vegeta.Results{} if err := results.Decode(in); err != nil { return err } all = append(all, results...) } all.Sort() out, err := file(output, true) if err != nil { return err } defer out.Close() if data, err := rep(all); err != nil { return err } else if _, err := out.Write(data); err != nil { return err } return nil }
// report validates the report arguments, sets up the required resources // and writes the report func report(opts *reportOpts) error { rep, ok := reporters[opts.reporter] if !ok { log.Println("Reporter provided is not supported. Using text") rep = vegeta.ReportText } var all vegeta.Results for _, input := range strings.Split(opts.inputf, ",") { in, err := file(input, false) if err != nil { return err } var results vegeta.Results if err = results.Decode(in); err != nil { return err } in.Close() all = append(all, results...) } all.Sort() out, err := file(opts.outputf, true) if err != nil { return err } defer out.Close() data, err := rep(all) if err != nil { return err } _, err = out.Write(data) return err }