go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.14k stars 1.29k forks source link

required_if does not work with boolean fields (again) #1158

Closed ManiacMaxo closed 10 months ago

ManiacMaxo commented 10 months ago

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

issue

Code sample, to showcase or reproduce:

package main

import (
    "fmt"
    "github.com/go-playground/validator/v10"
)

type Config struct {
    Enabled  bool
    HostPort string `validate:"required_if=Enabled true"`
}

func main() {
    cfg := Config{
        Enabled: true,
        // HostPort: ":8080",
    }

    validate := validator.New()
    err := validate.Struct(cfg)
    if err != nil {
        fmt.Println("got error:", err)
    } else {
        fmt.Println("no error")
    }
}
ManiacMaxo commented 10 months ago

Seems I was running an older version (v10.4.1)