for example http://tt.com?x=name

I want to remove the x queryString for all incoming requests?does gin support this

thanks

Comment From: yousifnimah

Hello @lancedang, you can use middleware to remove x queryString for all incoming requests. check the following code snippet below:

package main

import (
    "github.com/gin-gonic/gin"
)

func main() {
    router := gin.Default()

    router.Use(RemoveQueryParam("x"))

    //Sample of route to check if x queryString has been removed
    router.GET("/", func(c *gin.Context) {
        c.JSON(200, c.Request.URL.Query())
    })

    router.Run(":8080")
}

// RemoveQueryParam Middleware to remove query string parameter
func RemoveQueryParam(param string) gin.HandlerFunc {
    return func(c *gin.Context) {
        values := c.Request.URL.Query()
        values.Del(param)
        c.Request.URL.RawQuery = values.Encode()
        c.Next()
    }
}