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:
parent
a4375c4991
commit
1ad37ae896
16
README.md
16
README.md
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user