Skip to content

Releases: cohesivestack/valgo

v0.7.1

27 Nov 16:29

Choose a tag to compare

What's Changed

Parent namespace invalidation support for IsValid()

IsValid() now supports parent namespaces in nested validation structures. When a nested field is invalid, all parent namespaces are automatically marked as invalid, enabling conditional checks at any level of the object graph.

What's new

  • Parent namespace tracking: When a field like "person.addresses[0].line1" is invalid, parent namespaces ("person", "person.addresses", "person.addresses[0]") are also marked as invalid
  • Improved IsValid() behavior: IsValid() is now parent-namespace awareness
  • Works with all namespace types: Supports dot-separated namespaces (In()) and indexed namespaces (InRow(), InCell())

Example

val := v.In("person",
  v.InRow("addresses", 0,
    v.Is(v.String("", "line1").Not().Blank()),
  ),
)

// Check validity at any namespace level
if !val.IsValid("person.addresses") {
  // Handle address validation errors
}

Benefits

  • Write conditional logic at any namespace level without checking individual leaf fields
  • More intuitive API for nested validation structures

v0.7.0

21 Sep 20:16
5ddd85d

Choose a tag to compare

Valgo v0.7.0 — Ergonomics + Type-safety

This release focuses on two things: (1) fluent control over validation flow and (2) type-safe validators that remove codegen and width-specific types. PR: #50

New validation helpers (sessions): InCell, If, When, Do

  • InCell(name, index, v) — Run validators in an indexed namespace (great for slices of primitives or flat tables). Errors are grouped like phones[2].number, keeping messages precise without manual prefixing.
  • If(condition, validation) — Conditionally merge another validation session. Perfect for optional blocks.
  • When(condition, func(val *Validation)) — Like If, but runs a function to build rules. Keeps linear, readable control-flow.
  • Do(func(val *Validation)) — Execute custom logic with access to the session (e.g., compute, branch, or attach custom errors).

Why this matters: these helpers eliminate boilerplate if trees around validation, preserve explicit intent, and keep error paths tied to the exact field/cell that failed.

Numeric validators — now generic, faster to use, easier to maintain

We replaced generated, width-specific validators with single generic types per family:

  • ValidatorInt[T ~int|~int8|~int16|~int32|~int64]
  • ValidatorUint[T ~uint|~uint8|~uint16|~uint32|~uint64]
  • ValidatorFloat[T ~float32|~float64]

New rules include Positive()/Negative() for integers and NaN(), Infinite(), Finite() for floats. Constructors like v.Int16(...), v.Uint64(...), v.Float32(...) still work and now return the generic types. You keep your call sites; declared types may need a tweak (see “Breaking changes”).

Why this matters: less API surface, clearer autocompletion, fewer mistakes during refactors, and no codegen to maintain.

Comparable & Typed validators

  • ValidatorComparable[T comparable] — Type-safe equality and membership: EqualTo, InSlice, plus Passing.
  • ValidatorTyped[T] — A type-safe alternative to Any when you want custom rules on your own domain types without losing compile-time checks; includes Passing(func(T) bool) and Nil() for pointer forms.

Why this matters: you keep Go’s type guarantees (no accidental cross-type comparisons) and still write concise, expressive rules.

Migration & breaking changes

  • Numeric validators: width-specific types (e.g., ValidatorInt16) are replaced by generics.

    • Before: var a ValidatorInt16
    • After: var a *ValidatorInt[int16]
      Constructors (v.Int16(...), etc.) are unchanged.
  • Any.EqualTo() is deprecated; use Comparable.EqualTo() to keep type-safety.

Quick examples

Validate items in a slice with stable error paths:

for i, phone := range phones {
  val = val.InCell("phones", i, v.Is(
    v.String(phone, "number").Not().Blank().OfLengthBetween(7, 15),
  ))
}

Conditionally attach rules with If / When:

val.
  If(hasMiddle, v.Is(v.String(m, "middle").OfLengthBetween(2, 50))).
  When(isTrial, func(vv *v.Validation) {
    vv.Is(v.Int(daysLeft, "days_left").GreaterThan(0))
  })

Comparable & Typed:

// Comparable
v.Is(v.Comparable(status, "status").InSlice([]Status{"active","paused"}))

// Typed custom rule
type Plan string
v.Is(v.Typed(plan, "plan").Passing(func(p Plan) bool { return p == "pro" || p == "team" }))

Bottom line: v0.7.0 gives you cleaner control-flow (InCell/If/When/Do), safer equality and domain rules (Comparable, Typed), and a smaller, more coherent numeric API with new positivity/NaN/∞ checks—without disrupting most call sites.

v0.6.0

05 Sep 16:19
af9e97e

Choose a tag to compare

What's Changed

  • Add rune length validators to support non-Latin alphabet languages by @mintc2 in #46
  • Feature/expand rune tests by @carlosforero in #48

New Contributors

Full Changelog: v0.5.0...v0.6.0

v0.5.0

23 Jul 23:00
f74e7fe

Choose a tag to compare

What's Changed

✨ New Error Handling Functions

This release introduces two new error handling functions for better Go integration:

ToError() Function

  • Returns validation errors as a standard Go error interface
  • Perfect for idiomatic error handling and integration with Go's native error system

ToValgoError() Function

  • Returns validation errors as a concrete *valgo.Error type
  • Provides access to rich, structured error details including per-field messages

Deprecated Error() Function

  • The existing Error() function is now deprecated and will be removed in v1.0
  • This resolves naming conflicts with Go's error interface implementation convention

🔧 Other Changes

📚 Quick Migration

Before (deprecated):

val.Error() // Will be removed in v1.0

After:

val.ToError()      // For standard error handling
val.ToValgoError() // For detailed error information

Full Changelog: v0.4.2...v0.5.0

v0.4.2

24 Jun 13:35
3e22d20

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.4.1...v0.4.2

v0.4.1

08 Apr 11:26
e90fa82

Choose a tag to compare

What's Changed

New Contributors

  • @gaby made their first contribution in #20

Full Changelog: v0.4.0...v0.4.1

v0.4.0

29 Mar 00:43
3679d79

Choose a tag to compare

What's Changed

  • Variadic Parameters for Is and Check: The Is and Check functions now accept variadic parameters, streamlining validation by enabling multiple validators in a single call. This enhancement simplifies the validation process, reduces code verbosity, and promotes the reuse of validation logic across projects. For more details, see PR #19.

Full Changelog: v0.3.0...v0.4.0

v0.3.0

17 Mar 06:37

Choose a tag to compare

What's Changed

New Contributors

  • @amsal made their first contribution in #15

Full Changelog: v0.2.4...v0.3.0

v0.2.4

09 Apr 12:21

Choose a tag to compare

What's Changed

This Release makes validationFactory type public: The validationFactory type has been made public and renamed to ValidationFactory, enhancing flexibility and enabling developers to reuse the factory more effectively in various scenarios.

Full Changelog: v0.2.3...v0.2.4

v0.2.3

17 Mar 19:38
0b89658

Choose a tag to compare

What's Changed

Full Changelog: v0.2.2...v0.2.3