From 6acbd657ebf4acb85991308f3d0d300917172f5b Mon Sep 17 00:00:00 2001 From: Tobias Dillig Date: Wed, 28 Apr 2021 23:30:28 +0200 Subject: [PATCH] fix: hotfix for #2 --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index dd89623..0d9d47b 100644 --- a/main.go +++ b/main.go @@ -72,10 +72,17 @@ func main() { c.JSON(http.StatusOK, gin.H{"data": url}) }) - r.GET("/:id", func(c *gin.Context) { + // TODO: this is a quick fix for the problem described here: https://github.com/gin-gonic/gin/issues/2696 + // this should be fixed as soon as possible + r.NoRoute(func(c *gin.Context) { + if c.Request.Method != "GET" { + c.JSON(http.StatusMethodNotAllowed, gin.H{"error": "method not allowed!"}) + return + } var url models.Url + path := c.Request.URL.Path[1:] - if err := models.DB.First(&url, "id = ?", c.Param("id")).Error; err != nil { + if err := models.DB.First(&url, "id = ?", path).Error; err != nil { c.JSON(http.StatusNotFound, gin.H{"error": "Record not found!"}) return }