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

Let httpx.Parse() support parsing anonymous field of a struct #4240

Open
Linde7777 opened this issue Jul 10, 2024 · 0 comments
Open

Let httpx.Parse() support parsing anonymous field of a struct #4240

Linde7777 opened this issue Jul 10, 2024 · 0 comments

Comments

@Linde7777
Copy link

Linde7777 commented Jul 10, 2024

Is your feature request related to a problem? Please describe.
I am using anonymous field to reduce verbose code, and I found that httpx.Parse() can't go into the anonymous field to parse the tag(like "form", which is used for query parameter)

type UserListRequest struct {
	bizutils.ListReq
	SearchCondition
}

type ListReq struct {
	Page  int64 `form:"page" validate:"required,min=1"`
	Limit int64 `form:"limit" validate:"required,min=5,max=20"`
}

type SearchCondition struct {
	Email       string `form:"email,optional" validate:"omitempty,email"`
	PhoneNumber string `form:"phone_number,optional"`
}
var req types.UserListRequest
if err := httpx.Parse(r, &req); err != nil {
	bizutils.RespBadRequest(w, err)
	return
}

the error will be: field "page" is not set

Describe the solution you'd like
I guess it would be easier to use recursive to implement this feature

@Linde7777 Linde7777 changed the title Make httpx.Parse() can parse anonymous field of a struct Let httpx.Parse() support parsing anonymous field of a struct Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant