My request is failing from other service even I am passing required query string parameters. Here is validation code:
type ActionByRuleRequest struct {
Code string `json:"code" form:"code" query:"code" validate:"required,oneof=gde cse scc"`
Name string `json:"name" form:"name" query:"name" validate:"required"` // Monitoring rule name
}
Here is validating query string with validation
func GetActionByRule(c echo.Context) error {
// Get parameters from the query string
req := new(model.ActionByRuleRequest)
err := c.Bind(req);
if err != nil {
log.Println(err)
error := model.Error{
Message: err.Error(),
}
responseError := &model.ResponseError{
Status: http.StatusBadRequest,
Code: "INVALID_INPUT",
}
responseError.Errors = append(responseError.Errors, error)
return echo.NewHTTPError(http.StatusBadRequest, responseError)
}
// Validate input
log.Printf("[/action_by_rule] 00000000000 get req = %#v
", req)
v := validator.New()
err = v.Struct(req);
if err == nil {
log.Println("Input valid")
} else {
log.Println("Input validation failed:", err)
}
}
Request URL:'http://127.0.0.1:3015/action?code=csf&name=tbiubi-csf-rule'
Error:
Key: 'ActionByRuleRequest.Code' Error:Field validation for 'Code' failed on the 'required' tag
Key: 'ActionByRuleRequest.Name' Error:Field validation for 'Name' failed on the 'required' tag