Skip to content

Minor Release v1.1.7

Latest

Choose a tag to compare

@BryanMwangi BryanMwangi released this 02 Jul 20:49

What's changed

BindJSON — opt-in required validation

Fields are now optional by default. Mark a field required with the pine:"required" tag:

type CreateUserRequest struct {
    Name  string   `json:"name"  pine:"required"` // must be non-empty
    Email string   `json:"email" pine:"required"` // must be non-empty
    Tags  []string `json:"tags"`                  // optional — empty slice accepted
    Age   int      `json:"age"`                   // optional — zero accepted
}

if err := c.BindJSON(req); err != nil {
    // only fires if a pine:"required" field is missing or empty
}

Migration
⚠️ Breaking change for callers who relied on implicit required validation.

Add pine:"required" to any field that must be present. Fields with

// Before (all fields implicitly required)
type Body struct {
    Name string `json:"name"`
}

// After (opt in explicitly)
type Body struct {
    Name string `json:"name" pine:"required"`
}

Full changelog: https://github.com/BryanMwangi/pine/blob/main/CHANGELOG.md