On Thursday, 2 January 2020 15:01:15 UTC+9, Glen Huang wrote:
>
> @Ben
>
> My real world use case is that I have these types that dealing with user 
> signing up/loging in
>
> type LogIn struct {
>   Name string
>   Password string
> }
>
> type SignUp struct {
>   Name string
>   Password string
>   Gender string
> }
>   
>
> I was hoping that I cloud embed LogIn inside SignUp, to eliminate 
> duplicate fields. LogIn has a UnmarshalJSON that, for example, decrypts 
> password after parsing it, which ideally could be picked up by SignUp 
> automatically, without me having to wrap another UnmarshalJSON for SignUp. 
>

In my opinion that's a misuse of UnmarshalJSON. The decrypting should be 
separate from the unmarshalling, or even better just use the built in 
unmarshalling and decrypt it somewhere else.
 

> Is achieving this shortcut through embedding possible?
>

Sorry but I don't know. I tried working on your problem out of interest, 
and I posted a response because I thought the behaviour displayed was 
unexpected.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fc98c5db-b898-4aa2-bbd4-8c9165d58fb1%40googlegroups.com.

Reply via email to