Skip to content
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

🤗 [Question]: v3 bind query and json make a mistake #3253

Open
3 tasks done
cccqcccq opened this issue Dec 17, 2024 · 3 comments
Open
3 tasks done

🤗 [Question]: v3 bind query and json make a mistake #3253

cccqcccq opened this issue Dec 17, 2024 · 3 comments

Comments

@cccqcccq
Copy link

cccqcccq commented Dec 17, 2024

Question Description

I'm having an issue when I need to bind both query and json in v3

type ProductListReq struct {
	Page   int32  `json:"-"`
	Size   int32  `json:"-"`
	Search string `json:"search"`
}

func (u *Product) List(c fiber. Ctx) error {
	var req ProductListReq
	if err := c.Bind(). Query(&req); err != nil {
		return u.Error(c, fiber. StatusBadRequest, utils. Translate(err))
	}
	if c.Get("Content-Type") == "application/json" {
		if err := c.Bind(). JSON(&req); err != nil {
			return u.Error(c, fiber. StatusBadRequest, utils. Translate(err))
		}
	}
	return nil
}

This is the correct code, but when I remove it
if c.Get("Content-Type") == "application/json"
I'm getting an error:invalid character '' looking for beginning of value

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
Copy link

welcome bot commented Dec 17, 2024

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@gaby
Copy link
Member

gaby commented Dec 20, 2024

@efectn Any ideas?

@cccqcccq
Copy link
Author

It should be added that json is also passed in the query, for example: url?page=1&size=9&search={keyword:'key'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants