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

Create BindValidate for context #776

Closed
hayeah opened this issue Dec 18, 2016 · 1 comment
Closed

Create BindValidate for context #776

hayeah opened this issue Dec 18, 2016 · 1 comment

Comments

@hayeah
Copy link

hayeah commented Dec 18, 2016

Bind and Validate are both customizable. It might be nice to provide a sugar method to do both:

func (c *Context) BindValidate(ptr interface{}) error {
	err := c.Bind(c)
	if err != nil {
		return err
	}

	return c.Validate(ptr)
}
@hayeah
Copy link
Author

hayeah commented Dec 18, 2016

I just realized that I can do this easily with CustomBinder:

func (cb *CustomBinder) Bind(i interface{}, c echo.Context) (err error) {
	b := &echo.DefaultBinder{}

	if err = b.Bind(i, c); err != nil {
		return
	}

	return validate.Struct(i)
}

@hayeah hayeah closed this as completed Dec 18, 2016
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