Last active
October 4, 2019 06:43
-
-
Save sumanentc/d9d960a7f7a8634aa10953eff8628cfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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