-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter 无法对切片中的元素应用 #262
Labels
enhancement
New feature or request
Comments
如果类型改成 float64, 并且注释掉 filter 规则,可以正常通过验证: package main
import (
"fmt"
"github.com/gookit/validate"
)
type ContainerPort struct {
ContainerStart float64 `json:"container_start"`
ContainerEnd float64 `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", "float")
v2.AddRule("ports.*.container_end", "float")
v2.AddRule("ports.*.protocol", "string")
if v2.Validate() {
fmt.Println(v2.SafeData())
} else {
fmt.Println(v2.Errors)
}
} |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
System (please complete the following information):
linux
[e.g. linux, macOS]1.22
[e.g.1.13
]1.5.2
[e.g.1.1.1
]Describe the bug
filter 无法对切片中的元素应用,报错:
_filter: ports.*.container_start: convert value type error
To Reproduce
Expected behavior
正确将切片中的子元素转为 int 类型。
Screenshots
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: