Skip to content

Commit 4c62f9b

Browse files
authored
feat: allow answerId in shorthand overflow URL (#91)
1 parent e826466 commit 4c62f9b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func main() {
5252

5353
r.GET("/a/:id", routes.RedirectShortenedOverflowURL)
5454
r.GET("/q/:id", routes.RedirectShortenedOverflowURL)
55+
r.GET("/q/:id/:answerId", routes.RedirectShortenedOverflowURL)
5556

5657
r.GET("/questions/:id", func(c *gin.Context) {
5758
// redirect user to the question with the title

src/routes/shortened.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
func RedirectShortenedOverflowURL(c *gin.Context) {
1313
id := c.Param("id")
14+
answerId := c.Param("answerId")
1415

1516
// fetch the stack overflow URL
1617
client := resty.New()
@@ -20,7 +21,7 @@ func RedirectShortenedOverflowURL(c *gin.Context) {
2021
}),
2122
)
2223

23-
resp, err := client.R().Get(fmt.Sprintf("https://www.stackoverflow.com/a/%s", id))
24+
resp, err := client.R().Get(fmt.Sprintf("https://www.stackoverflow.com/a/%s/%s", id, answerId))
2425
if err != nil {
2526
c.HTML(400, "home.html", gin.H{
2627
"errorMessage": "Unable to fetch stack overflow URL",

0 commit comments

Comments
 (0)