labstack/echox

Docs for request example, Validate Data, error is --> not enough arguments in call to validator.New

johnson7788 opened this issue · 0 comments

Hi Guys
Please help check below issue. thanks!

https://echo.labstack.com/guide/request
example is Validate Data

package main

import (
"gopkg.in/go-playground/validator.v8"
"github.com/labstack/echo"
"net/http"
)

type (
User struct {
Name string json:"name" validate:"required"
Email string json:"email" validate:"required,email"
}

CustomValidator struct {
	validator *validator.Validate
}

)

func (cv *CustomValidator) Validate(i interface{}) error {
return cv.validator.Struct(i)
}

func main() {
e := echo.New()
e.Validator = &CustomValidator{validator: validator.New()}
e.POST("/users", func(c echo.Context) (err error) {
u := new(User)
if err = c.Bind(u); err != nil {
return
}
if err = c.Validate(u); err != nil {
return
}
return c.JSON(http.StatusOK, u)
})
e.Logger.Fatal(e.Start(":1323"))
}

command-line-arguments

./server3.go:26:57: not enough arguments in call to validator.New
have ()
want (*validator.Config)