// Handler is a route handler for '/movie.:format' route func Handler(c *gin.Context) { requestType := c.Param("format") term := c.Request.PostFormValue("text") log.Printf("Movie Query: %s", term) movie, err := lookupMovie(term) switch requestType { case "json": if err != nil { c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()}) } else { c.IndentedJSON(http.StatusOK, movie) } case "slack": text, err := formatSlackResp(movie) if err != nil { c.String(http.StatusNotFound, "Not Found") } c.String(http.StatusOK, text) default: c.JSON(http.StatusUnsupportedMediaType, nil) } }
// Handler is a route handler for '/movie.:format' route func Handler(c *gin.Context) { requestType := c.Param("format") text := c.Request.PostFormValue("text") operator, circle := parsedReqText(text) log.Printf("Recharge Query:: Circle := %s, Operator := %s", circle, operator) var list []Plan list, err := findPlans(circle, operator) switch requestType { case "json": if err != nil { c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()}) } else { c.IndentedJSON(http.StatusOK, list) } case "slack": text, err := formatSlackResp(list) if err != nil { c.String(http.StatusNotFound, "Not Found") } c.String(http.StatusOK, text) default: c.JSON(http.StatusUnsupportedMediaType, nil) } }
// PostsHandler is a route handler for '/producthunt/posts.:format' route func PostsHandler(c *gin.Context) { requestType := c.Param("format") daysAgo, err := strconv.Atoi(c.Request.PostFormValue("text")) if err != nil { daysAgo = 0 } log.Printf("Days Ago: %d", daysAgo) posts, err := getPosts(daysAgo) switch requestType { case "json": if err != nil { c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()}) } else { c.IndentedJSON(http.StatusOK, posts) } case "slack": text, err := formatPostsSlackResp(posts) if err != nil { c.String(http.StatusNotFound, "Not Found") } c.String(http.StatusOK, text) default: c.JSON(http.StatusUnsupportedMediaType, nil) } }
// Handler is a route handler for '/excuse.:format' route func Handler(c *gin.Context) { requestType := c.Param("format") excuse, err := getAnExcuse() switch requestType { case "json": if err != nil { c.JSON(http.StatusNotFound, gin.H{"Response": err.Error()}) } else { c.IndentedJSON(http.StatusOK, excuse) } case "slack": if err != nil { c.String(http.StatusNotFound, "> I am not feeling well\n") } c.String(http.StatusOK, "\n> "+excuse.Text+"\n") default: c.String(http.StatusUnsupportedMediaType, "") } }