You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeTypeFromTostruct {
StartDatestring`json:"startDate" url:"startDate" param:"startDate" validate:"required,iso_8601_date"`EndDatestring`json:"endDate" url:"endDate" param:"endDate" validate:"required,iso_8601_date"`
}
v1.Get("/stats", func(ctx iris.Context) {
vartTypeFromToerr:=ctx.ReadQuery(&t)
// To ignore errors of "required" or when unexpected values are passed to the query,// use the iris.IsErrPath.// It can be ignored, e.g:// if err!=nil && !iris.IsErrPath(err) { ... return }//// To receive an error on EMPTY query when ReadQuery is called// you should enable the `FireEmptyFormError/WithEmptyFormError` ( see below).// To check for the empty error you simple compare the error with the ErrEmptyForm, e.g.:// err == iris.ErrEmptyForm, so, to ignore both path and empty errors, you do:// if err!=nil && err != iris.ErrEmptyForm && !iris.IsErrPath(err) { ctx.StopWithError(...); return }iferr!=nil {
// Handle the error, below you will find the right way to do that...iferrs, ok:=err.(validator.ValidationErrors); ok {
// Wrap the errors with JSON format, the underline library returns the errors as interface.validationErrors:=wrapValidationErrors(errs)
// Fire an application/json+problem response and stop the handlers chain.ctx.StopWithProblem(iris.StatusBadRequest, iris.NewProblem().
Title("Validation error").
Detail("One or more fields failed to be validated").
Type("/user/validation-errors").
Key("errors", validationErrors))
return
}
// It's probably an internal JSON error, let's dont give more info here.ctx.StopWithStatus(iris.StatusInternalServerError)
return
}
ctx.Json(iris.Map{
"demo": true,
})
}
call the url /stats without ?startDate=2024-01-01&endDate=2024-02-01
Expected behavior
If no query parms are there with the names it shoulf fire the errors
Screenshots
Desktop (please complete the following information):
OS: windows
iris.Version
main
Additional context
The text was updated successfully, but these errors were encountered:
Describe the bug
The Validator dont fire on
ctx.ReadQuery(...)
I was doing it similar to
iris/_examples/request-body/read-json-struct-validation/main.go
Line 2 in 6776bf0
To Reproduce
call the url /stats without
?startDate=2024-01-01&endDate=2024-02-01
Expected behavior
If no query parms are there with the names it shoulf fire the errors
Screenshots
Desktop (please complete the following information):
iris.Version
Additional context
The text was updated successfully, but these errors were encountered: