[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread Th3x0d3r
Not as I expected, but it works,  Would 
it be possible not to use an specific type (*SomeMessage) an instead use 
interface{} type in assertion? 

On Tuesday, April 11, 2017 at 9:22:41 AM UTC-4, Th3x0d3r wrote:
>
> Hey there !
>
> How can i set the value of an interface{} parameter from other interface{} 
> source
>
> Playground : https://play.golang.org/p/utwO2Ru4Eq
>
> Output expected:
>
> Val 1: &{XML}
> Val 2: &{XML}
>
>
> Thanks 
>

-- 
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.


[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread pierre . curto
In Go, everything is passed by value, including interfaces (empty or not).
A quick overview 
at http://goinbigdata.com/golang-pass-by-pointer-vs-pass-by-value/.

So, you cannot change the value pointed to by an interface unless you 
"unbox" it: https://play.golang.org/p/uzccweBdzV

Further reading:
to understand interfaces inner workings: 
https://research.swtch.com/interfaces, even though I think that the 
interface value is now always a pointer.


Le mardi 11 avril 2017 16:15:38 UTC+2, Th3x0d3r a écrit :
>
> It works this way, but need to use 
> the GetMessage interface value 
>

-- 
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.


[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread James Bardin


On Tuesday, April 11, 2017 at 10:10:25 AM UTC-4, Th3x0d3r wrote:
>
> AFAIK empty interfaces{} are passed by reference
>
>
Nothing in go is "pass by reference". The interface value is always copied. 

-- 
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.


[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread Th3x0d3r
It works this way, but need to use 
the GetMessage interface value 

-- 
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.


[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread Th3x0d3r
I would but need to use empty interfaces{} as parameters

On Tuesday, April 11, 2017 at 9:52:20 AM UTC-4, Pierre Curto wrote:
>
> Either pass around the pointer to your struct or use a dedicated interface 
> to alter the struct contents.
> Examples of each here  and there 
> .
>
> Le mardi 11 avril 2017 15:22:41 UTC+2, Th3x0d3r a écrit :
>>
>> Hey there !
>>
>> How can i set the value of an interface{} parameter from other 
>> interface{} source
>>
>> Playground : https://play.golang.org/p/utwO2Ru4Eq
>>
>> Output expected:
>>
>> Val 1: &{XML}
>> Val 2: &{XML}
>>
>>
>> Thanks 
>>
>

-- 
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.


[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread Th3x0d3r
AFAIK empty interfaces{} are passed by reference

On Tuesday, April 11, 2017 at 9:46:00 AM UTC-4, T L wrote:
>
>
>
> On Tuesday, April 11, 2017 at 9:22:41 PM UTC+8, Th3x0d3r wrote:
>>
>> Hey there !
>>
>> How can i set the value of an interface{} parameter from other 
>> interface{} source
>>
>> Playground : https://play.golang.org/p/utwO2Ru4Eq
>>
>> Output expected:
>>
>> Val 1: &{XML}
>> Val 2: &{XML}
>>
>>
>> Thanks 
>>
>
>
> func GetClient(method string, resp interface{}) error {
> result := GetMessage("XML")
> resp = result
> fmt.Printf("Val 1: %v\n", resp)
> return nil
> }
>
> resp is an input parameter, when you pass a value as this parameter into 
> the GetClient function, 
> it is copied into the call in fact.
> Modifications on this copy will not be reflected to the original value 
> outside of the called function.
>
> If you do want to make the modifications visible to caller, you can return 
> it as an output result, or use a pointer parameter instead.
>
>  
>

-- 
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.


[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread pierre . curto
Either pass around the pointer to your struct or use a dedicated interface 
to alter the struct contents.
Examples of each here  and there 
.

Le mardi 11 avril 2017 15:22:41 UTC+2, Th3x0d3r a écrit :
>
> Hey there !
>
> How can i set the value of an interface{} parameter from other interface{} 
> source
>
> Playground : https://play.golang.org/p/utwO2Ru4Eq
>
> Output expected:
>
> Val 1: &{XML}
> Val 2: &{XML}
>
>
> Thanks 
>

-- 
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.


[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread T L


On Tuesday, April 11, 2017 at 9:22:41 PM UTC+8, Th3x0d3r wrote:
>
> Hey there !
>
> How can i set the value of an interface{} parameter from other interface{} 
> source
>
> Playground : https://play.golang.org/p/utwO2Ru4Eq
>
> Output expected:
>
> Val 1: &{XML}
> Val 2: &{XML}
>
>
> Thanks 
>


func GetClient(method string, resp interface{}) error {
result := GetMessage("XML")
resp = result
fmt.Printf("Val 1: %v\n", resp)
return nil
}

resp is an input parameter, when you pass a value as this parameter into 
the GetClient function, 
it is copied into the call in fact.
Modifications on this copy will not be reflected to the original value 
outside of the called function.

If you do want to make the modifications visible to caller, you can return 
it as an output result, or use a pointer parameter instead.

 

-- 
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.