Merge branch 'origin/main'
This commit is contained in:
commit
f7209802ce
1
main.go
1
main.go
@ -52,6 +52,7 @@ func main() {
|
|||||||
|
|
||||||
r.GET("/a/:id", routes.RedirectShortenedOverflowURL)
|
r.GET("/a/:id", routes.RedirectShortenedOverflowURL)
|
||||||
r.GET("/q/:id", routes.RedirectShortenedOverflowURL)
|
r.GET("/q/:id", routes.RedirectShortenedOverflowURL)
|
||||||
|
r.GET("/q/:id/:answerId", routes.RedirectShortenedOverflowURL)
|
||||||
|
|
||||||
r.GET("/questions/:id", func(c *gin.Context) {
|
r.GET("/questions/:id", func(c *gin.Context) {
|
||||||
// redirect user to the question with the title
|
// redirect user to the question with the title
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
func RedirectShortenedOverflowURL(c *gin.Context) {
|
func RedirectShortenedOverflowURL(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
answerId := c.Param("answerId")
|
||||||
|
|
||||||
// fetch the stack overflow URL
|
// fetch the stack overflow URL
|
||||||
client := resty.New()
|
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 {
|
if err != nil {
|
||||||
c.HTML(400, "home.html", gin.H{
|
c.HTML(400, "home.html", gin.H{
|
||||||
"errorMessage": "Unable to fetch stack overflow URL",
|
"errorMessage": "Unable to fetch stack overflow URL",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user