Documentation
¶
Overview ¶
Package fieldval holds the internal value carrier (FieldValue) that flows through the validating pipeline. It depends only on goutil and the sibling internal/reflectx package, never on the validate root package, keeping the dependency direction one-way (root -> internal/fieldval).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldValue ¶
type FieldValue struct {
Src any // original value from the data source
// contains filtered or unexported fields
}
FieldValue is an internal value carrier that flows through the validating pipeline. It holds the raw value together with its lazily-built reflect.Value, so the same underlying value is not repeatedly re-reflected (reflect.ValueOf) at each pipeline stage (痛点 A / B in docs/validate-v2-design.md §4.3).
All computation is lazy and cached: rv/rt/real and the zero/empty tri-state flags are only computed on first access. Designed for single-goroutine use within one validation pass (a *Validation is not shared concurrently).
func New ¶
func New(name string, src any) *FieldValue
New builds a FieldValue from a plain any value (map/form sources). The reflect.Value is built lazily on first need.
func NewRV ¶
func NewRV(name string, rv reflect.Value) *FieldValue
NewRV builds a FieldValue from an already-available reflect.Value (struct source). It avoids an Interface()->ValueOf round-trip. The `src` is kept as the boxed value for callers/validators that still consume `any`.
NOTE: reserved for P2 (struct path will pass the cached reflect.Value here); defined now so the carrier API is complete.
func (*FieldValue) IsEmpty ¶
func (f *FieldValue) IsEmpty() bool
IsEmpty reports whether the value is empty, giving results identical to the public IsEmpty(any) for the same input — including the untyped-nil and string fast paths — but reusing rV() so the value is reflected at most once.
func (*FieldValue) IsZero ¶
func (f *FieldValue) IsZero() bool
IsZero reports whether the value is the zero value for its type, matching the reflect.Value.IsZero() semantics used by StructData.TryGet. Lazy + cached.
func (*FieldValue) RT ¶
func (f *FieldValue) RT() reflect.Type
RT returns the reflect.Type of RV(), lazily built and cached.
func (*FieldValue) RV ¶
func (f *FieldValue) RV() reflect.Value
RV returns reflect.ValueOf(src), lazily built and cached.
If src is any(nil) the resulting reflect.Value is invalid; in that case it returns nilRVal — identical to the fix at callValidatorValue (validating.go), so fv.Call() won't panic on an Invalid kind (#125).
func (*FieldValue) RealV ¶
func (f *FieldValue) RealV() reflect.Value
RealV returns the de-pointered reflect.Value.
Semantics are kept byte-for-byte identical to the previous inline handling in callValidatorValue (its only P1 consumer): a single non-nil pointer level is dereferenced; a nil pointer is left as-is (so typed-nil keeps its pointer type). Deeper pointer levels are intentionally NOT unwrapped here to preserve 100% behavior equivalence with the pre-refactor code.