feat: allow answerId in shorthand overflow URL (#91)

This commit is contained in:
httpjamesm 2024-03-09 12:09:17 -05:00 committed by GitHub
parent e82646635e
commit 4c62f9bc4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -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

View File

@ -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",