validator

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package validator provides a unified validation framework for aix components.

It defines shared types for representing validation issues (errors, warnings, info) and results across different domains like Skills, MCP servers, and Agents.

Core Concepts

  • Severity: Distinguishes between blocking errors and non-blocking warnings.
  • Issue: Represents a single validation problem with field context.
  • Result: Aggregates multiple issues and provides helper methods.

Basic Usage

result := &validator.Result{}
if name == "" {
	result.AddError("name", "is required", name)
}

if result.HasErrors() {
	// handle validation failure
}

Package validator provides a unified validation framework for aix.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format string

Format specifies the output format for validation reports.

const (
	// FormatText produces human-readable text output.
	FormatText Format = "text"
	// FormatJSON produces machine-readable JSON output.
	FormatJSON Format = "json"
)

type Issue

type Issue struct {
	// Severity indicates the impact of the issue.
	Severity Severity
	// Field identifies the field with the issue (optional).
	Field string
	// Message is a human-readable description of the problem.
	Message string
	// Value is the actual value that failed validation (optional).
	Value any
	// Context is additional platform-specific or domain-specific context.
	Context map[string]string
}

Issue represents a single validation problem.

func (Issue) Error

func (i Issue) Error() string

Error implements the error interface.

type Reporter

type Reporter struct {
	// contains filtered or unexported fields
}

Reporter formats and writes validation results.

func NewReporter

func NewReporter(out io.Writer, format Format) *Reporter

NewReporter creates a new Reporter.

func (*Reporter) Report

func (r *Reporter) Report(result *Result) error

Report writes the validation result to the output.

type Result

type Result struct {
	Issues []Issue
}

Result aggregates validation issues.

func (*Result) AddError

func (r *Result) AddError(field, message string, value any)

AddError adds an error issue to the result.

func (*Result) AddInfo

func (r *Result) AddInfo(field, message string, value any)

AddInfo adds an info issue to the result.

func (*Result) AddWarning

func (r *Result) AddWarning(field, message string, value any)

AddWarning adds a warning issue to the result.

func (*Result) Errors

func (r *Result) Errors() []Issue

Errors returns a slice of all issues with SeverityError.

func (*Result) HasErrors

func (r *Result) HasErrors() bool

HasErrors returns true if any issue has SeverityError.

func (*Result) HasWarnings

func (r *Result) HasWarnings() bool

HasWarnings returns true if any issue has SeverityWarning.

func (*Result) Warnings

func (r *Result) Warnings() []Issue

Warnings returns a slice of all issues with SeverityWarning.

type Severity

type Severity int

Severity represents the impact of a validation issue.

const (
	// SeverityError indicates a blocking validation failure.
	SeverityError Severity = iota
	// SeverityWarning indicates a recommended but non-blocking issue.
	SeverityWarning
	// SeverityInfo indicates an informational note.
	SeverityInfo
)

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL