3 ms·
There's a nice trick you can use to make your map[string]interface{} code a bit easier to write and arguably also to read (less {}s), useful especially when you
by akavel 5y ago
There's a nice trick you can use to make your map[string]interface{} code a bit easier to write and arguably also to read (less {}s), useful especially when you need e.g. to serialize some deeply nested JSON, for one-off request:
func doSomeRequest(...) {
type loose map[string]interface{}
payload, err := json.Marshal(loose{
"fooBar": true,
"nested": loose{
"subfield": bazArg,
},
})
// ...
}
I should really probably write some blog listing various tricks like this I'm using, but I still can't make myself do it...
- scruple 5y agoThat is a good trick and I have a place where I can use this idea to make something more clear. You should write that blog post!