Open vkstack opened 2 years ago
There are 2 approaches I have discovered so far.
func tokenprocessor(c *gin.Context) {
if x, ok := c.GetQuery("token"); ok {
if x[len(x)-1] != '"' {
x = x + "\""
}
if x[0] != '"' {
x = "\"" + x
}
fmt.Println(x)
val := c.Request.URL.Query()
val.Set("token", x)
c.Request.URL.RawQuery = val.Encode()
}
}
const defaultMemory = 32 << 20
type SpecialTokenBinder struct{}
var SpltokenBinder = SpecialTokenBinder{}
func (SpecialTokenBinder) Name() string { return "form" }
func (SpecialTokenBinder) Bind(req *http.Request, obj interface{}) error { if err := req.ParseForm(); err != nil { return err } if err := req.ParseMultipartForm(defaultMemory); err != nil { if err != http.ErrNotMultipart { return err } } if x := req.URL.Query().Get("token"); x != "" { if x[len(x)-1] != '"' { x = x + "\"" } if x[0] != '"' { x = "\"" + x } val := req.URL.Query() val.Set("token", x) req.URL.RawQuery = val.Encode() }
if err := binding.MapFormWithTag(obj, req.URL.Query(), "form"); err != nil {
return err
}
if binding.Validator != nil {
return binding.Validator.ValidateStruct(obj)
}
return nil
}
# Couldn't both of these have avoided?
Description
I have a base64
yJUaW1lIjoiMjAyMi0wOC0wNlQxODoxMzo1Ni45OTA3MjkrMDU6MzAifQo=
which decodes to{"Time":"2022-08-06T18:13:56.990729+05:30"}
Now I wanted to pass this encoded base64 in
queryparam
and unmarshal it to struct. But I found it was not happening. every time i tried, I got.Is there not any way to unmarshal it in struct while passing base64 encoded data in queryparams?
How to reproduce
*Updated Aug 6,2022 6:25 PM
Expectations
Actual result
Note
With Post I am getting expected response.
Environment
go version go1.19 darwin/amd64