Implemented the initial Go framework
This commit is contained in:
64
internal/report/report.go
Normal file
64
internal/report/report.go
Normal file
@@ -0,0 +1,64 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user