schema

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package schema implements a classmesh.Stage that validates a structured record's decoded Fields against a declared shape. It classifies records that violate the schema into a quarantine category, with a reason per violation, and escalates valid records with ErrUnclassified, so it sits in front of the real classification stages and routes malformed input aside.

Index

Constants

View Source
const Name = "schema"

Name identifies this stage in classifications, stats, and logs.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Path     string
	Required bool
	Type     Type
}

Field constrains one value, addressed by a path the fieldpath package understands. A Required field must be present; unless Type is Any, a present value must hold that type.

type Stage

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

Stage validates records against a set of Field constraints. Schemas whose paths share prefixes are classified through a prefix trie that walks each shared prefix once per record; the rest use a flat per-field walk, which the trie cannot beat when there is no prefix to share.

func New

func New(category string, fields []Field) (*Stage, error)

New compiles the field constraints. category names where violating records go; at least one field is required and every field needs a path. A trie is built only when it would save prefix descents over the flat walk.

func (*Stage) Classify

Classify implements classmesh.Stage: a record violating the schema is classified into the configured category with a reason per violation; a valid record returns ErrUnclassified so the cascade moves on. A valid record allocates nothing.

func (*Stage) Name

func (s *Stage) Name() string

Name implements classmesh.Stage.

type Type

type Type int

Type is the JSON type a field is expected to hold. Number matches what JSON decoding yields (float64 or json.Number).

const (
	Any Type = iota
	String
	Number
	Bool
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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