-
Notifications
You must be signed in to change notification settings - Fork 124
Open
Labels
enhancementNew feature or requestNew feature or request
Description
System (please complete the following information):
- OS:
linux[e.g. linux, macOS] - GO Version:
1.22[e.g.1.13] - Pkg Version:
1.5.2[e.g.1.1.1]
Describe the bug
filter 无法对切片中的元素应用,报错:
_filter: ports.*.container_start: convert value type error
To Reproduce
package main
import (
"fmt"
"github.com/gookit/validate"
)
type ContainerPort struct {
ContainerStart int `json:"container_start"`
ContainerEnd int `json:"container_end"`
Protocol string `json:"protocol"`
}
type ContainerCreate struct {
Ports []ContainerPort `json:"ports"`
}
func main() {
data := `{"ports":[{"container_start":80,"container_end":80,"host_start":88,"host_end":88,"host":"","protocol":"tcp"}]}`
v, _ := validate.FromJSON(data)
fmt.Println(v.Src())
v2 := v.Create()
v2.FilterRule("ports.*.container_start", "int")
v2.FilterRule("ports.*.container_end", "int")
v2.AddRule("ports.*.container_start", "int")
v2.AddRule("ports.*.container_end", "int")
v2.AddRule("ports.*.protocol", "string")
if v2.Validate() {
fmt.Println(v2.SafeData())
} else {
fmt.Println(v2.Errors)
}
}Expected behavior
正确将切片中的子元素转为 int 类型。
Screenshots
Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
