Skip to content

Instantly share code, notes, and snippets.

@sumanentc
Created October 4, 2019 08:55
Show Gist options
  • Save sumanentc/4aa256df56efcd0c8c93a8c1a88e306e to your computer and use it in GitHub Desktop.
Save sumanentc/4aa256df56efcd0c8c93a8c1a88e306e to your computer and use it in GitHub Desktop.
func AddCat(c echo.Context) error {
type Cat struct {
Name string `json:"name"`
Type string `json:"type"`
}
cat := Cat{}
defer c.Request().Body.Close()
err := json.NewDecoder(c.Request().Body).Decode(&cat)
if err != nil {
log.Fatalf("Failed reading the request body %s", err)
return echo.NewHTTPError(http.StatusInternalServerError, err.Error)
}
log.Printf("this is yout cat %#v", cat)
return c.String(http.StatusOK, "We got your Cat!!!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment