Skip to content

v0.9.0

Choose a tag to compare

@carlosforero carlosforero released this 15 Aug 14:01
· 6 commits to master since this release
f0c1343

Valgo v0.9.0

Valgo v0.9.0 modernizes the numeric constructor API around Go generics and introduces reusable stateless validation predicates.

Generalized numeric constructors

The primary numeric constructors now accept every type in their respective families:

  • Int() and IntP() support all signed integer widths.
  • Uint() and UintP() support all unsigned integer widths.
  • Float() and FloatP() support float32 and float64.
  • User-defined numeric types remain fully type-safe.
type Attempts int8

attempts := Attempts(3)
limit := uint32(100)
ratio := float32(0.75)

v.Int(attempts).Between(0, 5)
v.Uint(limit).GreaterThan(0)
v.Float(ratio).Between(0, 1)

The specialized constructors originated before Go supported generics. With Valgo now targeting modern Go versions, separate constructors for every numeric width no longer provide additional behavior or type safety.

The following constructors are now deprecated compatibility aliases:

  • Int8, Int16, Int32, Int64, and their pointer variants
  • Uint8, Uint16, Uint32, Uint64, and their pointer variants
  • Float32, Float64, and their pointer variants

Existing code continues to work. New code should use Int, Uint, Float, and their pointer forms.

Rune/RuneP and Byte/ByteP remain supported because they communicate semantic meaning rather than only storage width.

Stateless validation predicates

The new github.com/cohesivestack/valgo/is package exposes Valgo’s built-in validation rules as type-safe boolean functions:

import "github.com/cohesivestack/valgo/is"

valid := !is.StringBlank(name) &&
  is.StringLengthBetween(name, 2, 80) &&
  is.IntGreaterOrEqualTo(stock, int16(0))

These predicates can be used in ordinary Go control flow, application-specific validation helpers, and third-party validators that want to share Valgo’s rule semantics while providing their own contexts, errors, chaining, or localization.

Valgo’s built-in validators now use the same predicates internally, keeping their behavior aligned.

Migrating

Migration only requires changing constructor names:

v.Int16(value)    // Deprecated
v.Int(value)      // Preferred

v.Float64P(&rate) // Deprecated
v.FloatP(&rate)   // Preferred

The inferred value type and available validation rules remain unchanged.

Documentation

  • Added a complete guide to stateless predicates.
  • Expanded numeric constructor and migration documentation.
  • Updated reusable-validation examples and the rule index.
  • Archived the v0.8.1 documentation under its own versioned route.
  • Updated the bundled Valgo Agent Skill for v0.9.0.