1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-13 01:30:31 +02:00

enabled validator, updated docs, fixed #298, fixed #438, fixed #305

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-12-12 17:19:41 -08:00
parent 70b5cfbb26
commit 01334bc7b2
4 changed files with 161 additions and 48 deletions

View File

@ -99,8 +99,12 @@ type (
// does it based on Content-Type header.
Bind(i interface{}) error
// Validate validates provided `i`. It is usually called after `Context#Bind()`.
// Validator must be registered using `Echo#Validator`.
Validate(i interface{}) error
// Render renders a template with data and sends a text/html response with status
// code. Templates can be registered using `Echo.Renderer`.
// code. Renderer must be registered using `Echo.Renderer`.
Render(code int, name string, data interface{}) error
// HTML sends an HTTP response with status code.
@ -350,6 +354,13 @@ func (c *context) Bind(i interface{}) error {
return c.echo.Binder.Bind(i, c)
}
func (c *context) Validate(i interface{}) error {
if c.echo.Validator == nil {
return ErrValidatorNotRegistered
}
return c.echo.Validator.Validate(i)
}
func (c *context) Render(code int, name string, data interface{}) (err error) {
if c.echo.Renderer == nil {
return ErrRendererNotRegistered