MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / FormatValidationJSON

Function FormatValidationJSON

cmd/gosqlx/internal/output/json.go:266–325  ·  view source on GitHub ↗

FormatValidationJSON converts validation results to JSON format. Generates structured JSON output from validation results, suitable for programmatic consumption, CI/CD integration, and automated processing. Parameters: - result: Validation results to format - inputFiles: Array of input file paths

(result *ValidationResult, inputFiles []string, includeStats bool)

Source from the content-addressed store, hash-verified

264//
265// FormatValidationJSON converts validation results to JSON format
266func FormatValidationJSON(result *ValidationResult, inputFiles []string, includeStats bool) ([]byte, error) {
267 output := &JSONValidationOutput{
268 Command: "validate",
269 Input: JSONInputInfo{
270 Type: determineInputType(inputFiles),
271 Files: inputFiles,
272 Count: len(inputFiles),
273 },
274 Status: determineStatus(result),
275 Results: JSONValidationResults{
276 Valid: result.InvalidFiles == 0,
277 TotalFiles: result.TotalFiles,
278 ValidFiles: result.ValidFiles,
279 InvalidFiles: result.InvalidFiles,
280 },
281 Errors: make([]JSONValidationError, 0),
282 }
283
284 // Add errors
285 for _, fileResult := range result.Files {
286 if fileResult.Error != nil {
287 errCode := extractErrorCode(fileResult.Error)
288 output.Errors = append(output.Errors, JSONValidationError{
289 File: fileResult.Path,
290 Message: fileResult.Error.Error(),
291 Code: errCode,
292 Type: categorizeByCode(errCode, fileResult.Error.Error()),
293 })
294 }
295 }
296
297 // Add statistics if requested
298 if includeStats {
299 throughputFPS := 0.0
300 if result.Duration.Seconds() > 0 {
301 throughputFPS = float64(result.TotalFiles) / result.Duration.Seconds()
302 }
303
304 throughputBPS := int64(0)
305 if result.Duration.Seconds() > 0 {
306 throughputBPS = int64(float64(result.TotalBytes) / result.Duration.Seconds())
307 }
308
309 output.Stats = &JSONValidationStats{
310 Duration: result.Duration.String(),
311 DurationMs: float64(result.Duration.Milliseconds()),
312 TotalBytes: result.TotalBytes,
313 ThroughputFPS: throughputFPS,
314 ThroughputBPS: throughputBPS,
315 }
316 }
317
318 // Marshal to JSON with indentation
319 data, err := json.MarshalIndent(output, "", " ")
320 if err != nil {
321 return nil, fmt.Errorf("failed to marshal validation JSON: %w", err)
322 }
323

Callers 4

validateRunFunction · 0.92
validateFromStdinFunction · 0.92

Calls 7

determineInputTypeFunction · 0.85
determineStatusFunction · 0.85
categorizeByCodeFunction · 0.85
extractErrorCodeFunction · 0.70
ErrorfMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45