Skip to content

Commit

Permalink
Merge branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
httpjamesm committed Mar 9, 2024
2 parents 880f27b + 4c62f9b commit f720980
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/routes/shortened.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand Down

0 comments on commit f720980

Please sign in to comment.