1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-05 00:58:47 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-05-05 21:55:49 -07:00
parent 54d2f72368
commit f80fff4efb
12 changed files with 176 additions and 147 deletions

View File

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