mirror of
https://github.com/labstack/echo.git
synced 2025-04-21 12:17:04 +02:00
Fixed crud example
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
a4375c4991
commit
1ad37ae896
16
README.md
16
README.md
@ -133,34 +133,34 @@ var (
|
|||||||
// Handlers
|
// Handlers
|
||||||
//----------
|
//----------
|
||||||
|
|
||||||
func createUser(c *echo.Context) *echo.HTTPError {
|
func createUser(c *echo.Context) error {
|
||||||
u := &user{
|
u := &user{
|
||||||
ID: seq,
|
ID: seq,
|
||||||
}
|
}
|
||||||
if he := c.Bind(u); he != nil {
|
if err := c.Bind(u); err != nil {
|
||||||
return he
|
return err
|
||||||
}
|
}
|
||||||
users[u.ID] = u
|
users[u.ID] = u
|
||||||
seq++
|
seq++
|
||||||
return c.JSON(http.StatusCreated, u)
|
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"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
return c.JSON(http.StatusOK, users[id])
|
return c.JSON(http.StatusOK, users[id])
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUser(c *echo.Context) *echo.HTTPError {
|
func updateUser(c *echo.Context) error {
|
||||||
u := new(user)
|
u := new(user)
|
||||||
if he := c.Bind(u); he != nil {
|
if err := c.Bind(u); err != nil {
|
||||||
return he
|
return err
|
||||||
}
|
}
|
||||||
id, _ := strconv.Atoi(c.Param("id"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
users[id].Name = u.Name
|
users[id].Name = u.Name
|
||||||
return c.JSON(http.StatusOK, users[id])
|
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"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
delete(users, id)
|
delete(users, id)
|
||||||
return c.NoContent(http.StatusNoContent)
|
return c.NoContent(http.StatusNoContent)
|
||||||
|
@ -24,34 +24,34 @@ var (
|
|||||||
// Handlers
|
// Handlers
|
||||||
//----------
|
//----------
|
||||||
|
|
||||||
func createUser(c *echo.Context) *echo.HTTPError {
|
func createUser(c *echo.Context) error {
|
||||||
u := &user{
|
u := &user{
|
||||||
ID: seq,
|
ID: seq,
|
||||||
}
|
}
|
||||||
if he := c.Bind(u); he != nil {
|
if err := c.Bind(u); err != nil {
|
||||||
return he
|
return err
|
||||||
}
|
}
|
||||||
users[u.ID] = u
|
users[u.ID] = u
|
||||||
seq++
|
seq++
|
||||||
return c.JSON(http.StatusCreated, u)
|
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"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
return c.JSON(http.StatusOK, users[id])
|
return c.JSON(http.StatusOK, users[id])
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUser(c *echo.Context) *echo.HTTPError {
|
func updateUser(c *echo.Context) error {
|
||||||
u := new(user)
|
u := new(user)
|
||||||
if he := c.Bind(u); he != nil {
|
if err := c.Bind(u); err != nil {
|
||||||
return he
|
return err
|
||||||
}
|
}
|
||||||
id, _ := strconv.Atoi(c.Param("id"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
users[id].Name = u.Name
|
users[id].Name = u.Name
|
||||||
return c.JSON(http.StatusOK, users[id])
|
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"))
|
id, _ := strconv.Atoi(c.Param("id"))
|
||||||
delete(users, id)
|
delete(users, id)
|
||||||
return c.NoContent(http.StatusNoContent)
|
return c.NoContent(http.StatusNoContent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user