Skip to content

Custom type validators

All golang validators allow to pass a custom type based on its value type. Bellow some valid examples.

type Status string
var status Status = "up"
val := v.Is(v.String(status).InSlice([]Status{"down", "up", "paused"}))
type Level int
var level Level = 1
val = v.Is(v.Int(level).LessThan(Level(2)))
type Stage int64
var stage Stage = 2
val := v.Is(v.NumberP(&stage).GreaterThan(Stage(1)))