39 lines
758 B
Go
39 lines
758 B
Go
package builtin
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"gitea.maximumdirect.net/eric/seriatim/internal/config"
|
|
"gitea.maximumdirect.net/eric/seriatim/internal/report"
|
|
)
|
|
|
|
type jsonOutputWriter struct{}
|
|
|
|
func (jsonOutputWriter) Name() string {
|
|
return "json"
|
|
}
|
|
|
|
func (jsonOutputWriter) Write(ctx context.Context, out any, rpt report.Report, cfg config.Config) ([]report.Event, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
file, err := os.Create(cfg.OutputFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
|
|
enc := json.NewEncoder(file)
|
|
enc.SetIndent("", " ")
|
|
if err := enc.Encode(out); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return []report.Event{
|
|
report.Info("output", "json", "wrote transcript JSON"),
|
|
}, nil
|
|
}
|