This is an automated archive.
The original was posted on /r/golang by /u/Consistent-Beach359 on 2023-09-01 19:43:22+00:00.
Hi all,
Ever found yourself writing a lot of code just to take request parameters or form fields, doing all the type conversion and then writing them to struct fields?
I thought that the json.Unmarshall([]byte, interface{}) had a really neat way of doing something similar. So, I wrote this little library that does exactly that.
type MyStruct struct { Search string
param:“search” } r := ... // the http.Request s := MyStruct{} err := reqbin.UnmarshallRequestForm(r, &s) // will look for a param called // search and map it to the field in s
Would be great to get some feedback. And if you find it useful, I would really appreciate if you would let me know.