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

feat: add c.BindCookie(obj) from cookie, and c.BindRequest(obj) from whole request #2805

Closed
wants to merge 1 commit into from

Conversation

tangx
Copy link

@tangx tangx commented Aug 3, 2021

  • With pull requests:
    • Open your pull request against master
    • Your pull request should have no more than two commits, if not you should squash them.
    • It should pass all tests in the available continuous integration systems such as GitHub Actions.
    • You should add/modify tests to cover your proposed code changes.
    • If your pull request contains a new feature, please document it on the README.

in order to bind values into object more simple.

  1. adding c.BindCookie(obj) to get parameters from cookies.

2.1. extract original Binding code into BindOnly and BindBodyOnly method, these two methods are only binding parameters into obj.
2.2. Bind method handler error from BindOnly method, then validate the obj.
2.3 BindOnly and BindBodyOnly are public methods, so that users can define their own logic without validation (binding:"required") checking trouble.

type Binding interface {
	Name() string
	Bind(*http.Request, interface{}) error
	BindOnly(*http.Request, interface{}) error
}

// BindingBody adds BindBody method to Binding. BindBody is similar with Bind,
// but it reads the body from supplied bytes instead of req.Body.
type BindingBody interface {
	Binding
	BindBody([]byte, interface{}) error
	BindBodyOnly([]byte, interface{}) error
}
  1. add a new method c.BindRequest to bind all parameters in request into obj at once. By using original Binding and BindingBody method now supported.
    now supports tag are form, cookie, header, body.

  2. add and pass testing functions.

  3. add documents about these 2 methods.

@tangx tangx closed this Aug 4, 2021
@sourcec0de sourcec0de mentioned this pull request Nov 12, 2022
5 tasks
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

Successfully merging this pull request may close these issues.

1 participant