Skip to content

Instantly share code, notes, and snippets.

@sumanentc
Last active October 4, 2019 06:43
Show Gist options
  • Save sumanentc/d9d960a7f7a8634aa10953eff8628cfd to your computer and use it in GitHub Desktop.
Save sumanentc/d9d960a7f7a8634aa10953eff8628cfd to your computer and use it in GitHub Desktop.
//http://localhost:8000/cats/json?name=arnold&type=fluffy
//data path variable accepts value as json/string
func GetCats(c echo.Context) error {
catName := c.QueryParam("name")
catType := c.QueryParam("type")
dataType := c.Param("data")
if dataType == "string" {
return c.String(http.StatusOK, fmt.Sprintf("your cat name is : %s\nand cat type is : %s\n", catName, catType))
} else if dataType == "json" {
return c.JSON(http.StatusOK, map[string]string{
"name": catName,
"type": catType,})
} else {
return c.JSON(http.StatusBadRequest, map[string]string{
"error": "Please specify the data type as Sting or JSON",})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment