1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

Fixed crud example

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-05-20 16:09:07 -07:00
parent a4375c4991
commit 1ad37ae896
2 changed files with 16 additions and 16 deletions

View File

@ -133,34 +133,34 @@ var (
// Handlers
//----------
func createUser(c *echo.Context) *echo.HTTPError {
func createUser(c *echo.Context) error {
u := &user{
ID: seq,
}
if he := c.Bind(u); he != nil {
return he
if err := c.Bind(u); err != nil {
return err
}
users[u.ID] = u
seq++
return c.JSON(http.StatusCreated, u)
}
func getUser(c *echo.Context) *echo.HTTPError {
func getUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
return c.JSON(http.StatusOK, users[id])
}
func updateUser(c *echo.Context) *echo.HTTPError {
func updateUser(c *echo.Context) error {
u := new(user)
if he := c.Bind(u); he != nil {
return he
if err := c.Bind(u); err != nil {
return err
}
id, _ := strconv.Atoi(c.Param("id"))
users[id].Name = u.Name
return c.JSON(http.StatusOK, users[id])
}
func deleteUser(c *echo.Context) *echo.HTTPError {
func deleteUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
delete(users, id)
return c.NoContent(http.StatusNoContent)

View File

@ -24,34 +24,34 @@ var (
// Handlers
//----------
func createUser(c *echo.Context) *echo.HTTPError {
func createUser(c *echo.Context) error {
u := &user{
ID: seq,
}
if he := c.Bind(u); he != nil {
return he
if err := c.Bind(u); err != nil {
return err
}
users[u.ID] = u
seq++
return c.JSON(http.StatusCreated, u)
}
func getUser(c *echo.Context) *echo.HTTPError {
func getUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
return c.JSON(http.StatusOK, users[id])
}
func updateUser(c *echo.Context) *echo.HTTPError {
func updateUser(c *echo.Context) error {
u := new(user)
if he := c.Bind(u); he != nil {
return he
if err := c.Bind(u); err != nil {
return err
}
id, _ := strconv.Atoi(c.Param("id"))
users[id].Name = u.Name
return c.JSON(http.StatusOK, users[id])
}
func deleteUser(c *echo.Context) *echo.HTTPError {
func deleteUser(c *echo.Context) error {
id, _ := strconv.Atoi(c.Param("id"))
delete(users, id)
return c.NoContent(http.StatusNoContent)