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
go-zero/rest/httpx/requests.go
Lines 134 to 139 in 4307ce4
由于 atomic.Value Strore 方法会 校验和首次存储的数据类型是否一致,此处存在 panic 风险。
atomic.Value
复现代码:
package main import ( "net/http" "github.com/zeromicro/go-zero/rest/httpx" ) func main() { httpx.SetValidator(Valid1{}) httpx.SetValidator(Valid2{}) // panic: sync/atomic: store of inconsistently typed value into Value } type Valid1 struct{} func (v Valid1) Validate(*http.Request, any) error { return nil } type Valid2 struct{} func (v Valid2) Validate(*http.Request, any) error { return nil }
SetValidator 方法改进建议:
SetValidator
func SetValidator(val Validator) { validator.Store(&validate{val: val}) } type validate struct { val Validator } func (v *validate) Validate(r *http.Request, data any) error { if v.val != nil { return v.val.Validate(r, data) } return nil }
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
go-zero/rest/httpx/requests.go
Lines 134 to 139 in 4307ce4
由于
atomic.Value
Strore 方法会 校验和首次存储的数据类型是否一致,此处存在 panic 风险。复现代码:
SetValidator
方法改进建议:The text was updated successfully, but these errors were encountered: