I am looking at https://godoc.org/github.com/gin-gonic/gin
documentation for a method which returns list of all the query parameters passed. There are methods which return value of a query parameter. Is there any method which returns list of all the query parameters passed ? It's ok if we don't get values. I am fetching the values of the query parameter using the following code. But this code can only check if the query parameter exists or not.
func myHandler(c *gin.Context) { // check for query params if queryParam, ok := c.GetQuery("startingIndex"); ok { if queryParam == "" { c.Header("Content-Type", "application/json") c.JSON(http.StatusNotFound, gin.H{"Error: ": "Invalid startingIndex on search filter!"}) c.Abort() return } } }
gin. Default() creates a Gin router with default middleware: logger and recovery middleware. Next, we make a handler using router. GET(path, handle) , where path is the relative path, and handle is the handler function that takes *gin. Context as an argument.
The gin Context is a structure that contains both the http. Request and the http. Response that a normal http. Handler would use, plus some useful methods and shortcuts to manipulate those. The gin engine is responsible for the creation (and reuse) of those contexts, in the same manner as the http.
Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.
You should be able to do c.Request.URL.Query()
which will return a Values which is a map[string][]string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With