Documentation
¶
Overview ¶
Package validate implements the tag-driven struct validator used by pkg/server (HTTP request binding) and pkg/mcp (typed-tool argument binding). It lives in internal/ so both packages can import it without creating a cycle between pkg/server and pkg/mcp.
The exported surface — Validate, ValidationError, FieldError — is re-exposed by pkg/server via type aliases for callers that consume the validator through the public server API.
Supported `validate` tag verbs:
required field must be a non-zero value min=N numeric/length >= N max=N numeric/length <= N len=N length exactly N (string/slice/map) email loose RFC 5322 sanity check on the local-part/domain oneof=A B C value must equal one of the (space-separated) options url must parse via net/url and have a scheme + host
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FieldError ¶
type FieldError struct {
Field string // JSON-tag name if present, else struct field name.
Tag string // The verb that failed (required, min, oneof, …).
Param string // The argument to the verb (the N in min=N, etc.).
Value any // The field's actual value.
Message string // Human-readable rendering.
}
FieldError describes one failed validation rule.
type ValidationError ¶
type ValidationError struct {
Fields []*FieldError
}
ValidationError is the aggregate error returned by Validate when one or more fields fail their rules.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements error. Returns a single line summarising all failures so it's safe to log without further formatting.
func (*ValidationError) HasField ¶
func (e *ValidationError) HasField(field string) bool
HasField reports whether the validation error has an entry for `field` (matched against FieldError.Field).