-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Open
Labels
type/proposalGot an idea for a feature that Gin doesn't have currently? Submit your idea here!Got an idea for a feature that Gin doesn't have currently? Submit your idea here!
Description
Feature Description
As of right now when getting a URL paramter in Gin the following must be done to change the type to an Integer.
func main() {
r := gin.Default()
r.GET("/add/:id", func(c *gin.Context) {
idStr := c.Param("id")
idInt, _ := strconv.Atoi(idStr)
c.JSON(http.StatusOK, gin.H{"id plus one": idInt + 1})
})
r.Run()
}I propose that there is a way to directly query the param as an Integer instead of the strconv.Atoi(idStr) each time. Like the following:
func main() {
r := gin.Default()
r.GET("/add/:id", func(c *gin.Context) {
id, err := c.ParamInt("id")
if err != nil {
return
}
c.JSON(http.StatusOK, gin.H{"id plus one": id + 1})
})
r.Run()
}Should be simple to add.
Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type/proposalGot an idea for a feature that Gin doesn't have currently? Submit your idea here!Got an idea for a feature that Gin doesn't have currently? Submit your idea here!