Files
seriatim/internal/report/report.go

65 lines
1.6 KiB
Go

package report
import (
"encoding/json"
"os"
)
// Severity classifies report events.
type Severity string
const (
SeverityInfo Severity = "info"
SeverityWarning Severity = "warning"
SeverityCorrected Severity = "corrected"
SeverityError Severity = "error"
)
// Event records a validation finding, correction, or pipeline action.
type Event struct {
Severity Severity `json:"severity"`
Stage string `json:"stage"`
Module string `json:"module"`
Message string `json:"message"`
}
// Report is the deterministic report artifact emitted by the framework.
type Report struct {
Metadata Metadata `json:"metadata"`
Events []Event `json:"events"`
}
// Metadata records the pipeline configuration that produced the report.
type Metadata struct {
Application string `json:"application"`
Version string `json:"version"`
InputReader string `json:"input_reader"`
InputFiles []string `json:"input_files"`
PreprocessingModules []string `json:"preprocessing_modules"`
PostprocessingModules []string `json:"postprocessing_modules"`
OutputModules []string `json:"output_modules"`
}
// Info constructs an informational report event.
func Info(stage string, module string, message string) Event {
return Event{
Severity: SeverityInfo,
Stage: stage,
Module: module,
Message: message,
}
}
// WriteJSON writes a deterministic JSON report.
func WriteJSON(path string, rpt Report) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
enc := json.NewEncoder(file)
enc.SetIndent("", " ")
return enc.Encode(rpt)
}