From 4c62f9bc4fc1f07852821005e2796aa03b240799 Mon Sep 17 00:00:00 2001 From: httpjamesm <51917118+httpjamesm@users.noreply.github.com> Date: Sat, 9 Mar 2024 12:09:17 -0500 Subject: [PATCH] feat: allow answerId in shorthand overflow URL (#91) --- main.go | 1 + src/routes/shortened.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d88a036..49c87ee 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,7 @@ func main() { r.GET("/a/:id", routes.RedirectShortenedOverflowURL) r.GET("/q/:id", routes.RedirectShortenedOverflowURL) + r.GET("/q/:id/:answerId", routes.RedirectShortenedOverflowURL) r.GET("/questions/:id", func(c *gin.Context) { // redirect user to the question with the title diff --git a/src/routes/shortened.go b/src/routes/shortened.go index ed1ad1e..9f608f8 100644 --- a/src/routes/shortened.go +++ b/src/routes/shortened.go @@ -11,6 +11,7 @@ import ( func RedirectShortenedOverflowURL(c *gin.Context) { id := c.Param("id") + answerId := c.Param("answerId") // fetch the stack overflow URL client := resty.New() @@ -20,7 +21,7 @@ func RedirectShortenedOverflowURL(c *gin.Context) { }), ) - resp, err := client.R().Get(fmt.Sprintf("https://www.stackoverflow.com/a/%s", id)) + resp, err := client.R().Get(fmt.Sprintf("https://www.stackoverflow.com/a/%s/%s", id, answerId)) if err != nil { c.HTML(400, "home.html", gin.H{ "errorMessage": "Unable to fetch stack overflow URL",