Re: [go-nuts] Re: Map to struct and vice versa

2021-05-17 Thread Nick Keets
Thanks everyone for your responses. structs is interesting, but archived, pre modules even. Using reflect directly also doesn't seem that bad and I do want error handling, so it looks like nothing beats JSON in terms of UI. On Mon, May 17, 2021 at 6:22 PM Howard C. Shaw III wrote: > The example

[go-nuts] Re: Map to struct and vice versa

2021-05-17 Thread Howard C. Shaw III
The examples given in other responses are great if you need to handle arbitrary or unknown maps and very much fit the 'easy way' part of your initial question. But you also asked at the end 'is there a more direct way?'. If you actually know what you are getting, you can code it entirely direc

[go-nuts] Re: Map to struct and vice versa

2021-05-17 Thread Mock ***
Hi Nick, I understand , please check if this pkg may help you https://github.com/fatih/structs, Thanks On Monday, May 17, 2021 at 2:58:54 PM UTC+5:30 Amnon wrote: > https://programmersought.com/article/93641771999/ > > On Monday, 17 May 2021 at 10:26:14 UTC+1 nick@gmail.com wrote: > >> Is

[go-nuts] Re: Map to struct and vice versa

2021-05-17 Thread Amnon
https://programmersought.com/article/93641771999/ On Monday, 17 May 2021 at 10:26:14 UTC+1 nick@gmail.com wrote: > Is there an easy way to go from a map to a struct and vice versa? e.g. > going from: > m := map[string]interface{}{"a": "x", "b": 5} > > to an instance of: > type T struct