We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
System (please complete the following information):
linux
1.22
1.13
1.5.2
1.1.1
Describe the bug
filter 无法对切片中的元素应用,报错: _filter: ports.*.container_start: convert value type error
_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.
The text was updated successfully, but these errors were encountered:
如果类型改成 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) } }
Sorry, something went wrong.
inhere
No branches or pull requests
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: