Hi,

Check if your method has the signature like this:
func (d DP) MyMethod(<my paramaters>) <my return types> { ... }


If so, change to this:
func (d *DP) MyMethod(<my paramaters>) <my return types> { ... }


I made this error so many times: a method called by value changes the value 
of the object and the change vanishes when the method returns, you must use 
a reference in order to preserve your changes to the struct fields. 

Cheers,
Luis Otavio de Colla Furquim


Em terça-feira, 30 de abril de 2019 11:31:14 UTC-3, mdmajid...@gmail.com 
escreveu:
>
> I have a map inside a struct like following - 
>
> type DP struct {
>    PI string
>    cat map[string]PS
> }
>
> Here, PS is another struct having two string fields.
>
> There is method where I create DP struct, initialise the map and put a 
> key-value pair to it.
> I append this DP struct to an array and return from the method to its 
> caller (the array to which i append is part of the object which is used to 
> invoke the method).
>
> In the method, I can debug and see that the struct got created with map 
> and its key value pair, however when the method returns to the caller, the 
> struct is there PI and cat initialised, but the key value pairs disappear 
> from the map. Is this behavior expected? 
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to