Ok, finally got it: https://go.dev/play/p/QFQOpqWsR6S

Thanks everyone, especially Axel

On Thursday, 24 November 2022 at 23:14:27 UTC Denis P wrote:

> Ok, looks like it doesn't work.
>
> I have got the following error:
> panic: interface conversion: interface {} is MyStruct, not *MyStruct
>
> So the actual code is this: https://go.dev/play/p/jBiPII7rOxG
>
> Cannot find out what is going on :-(
>
> On Thursday, 24 November 2022 at 22:29:21 UTC axel.wa...@googlemail.com 
> wrote:
>
>> Hi,
>>
>>
>> On Thu, Nov 24, 2022 at 11:16 PM Denis P <denis....@gmail.com> wrote:
>>
>>> Hi guys, tried to look everywhere and cannot find an answer.
>>>
>>> So literally I have this:
>>> ```
>>> var result interface{} = &MyStruct{}
>>>
>>> ...
>>>
>>> return result.(*MyStruct) // Error:  invalid operation: result 
>>> (variable of type *interface{}) is not an interface 
>>> ```
>>>
>>
>> No, offense, but you literally do not have that code, because the error 
>> message does not fit that code. In your code, `result` has type 
>> `interface{}`, whereas in the `return` statement, according to the error 
>> message, it has type `*interface{}`. Ergo, you are either shadowing 
>> `result` in-between, or the code is not equivalent.
>>
>> In any case, the immediate solution could be to dereference the pointer:
>> return (*result).(*MyStruct)
>>  
>>
>>>
>>> Is there any way to get the &MyStruct as a result?
>>>
>>> -- 
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/25da3c8f-6126-439a-904a-5fec59cb09f4n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/golang-nuts/25da3c8f-6126-439a-904a-5fec59cb09f4n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
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/ee00cfa3-cdcb-4756-9cf6-9cfcc9abbf12n%40googlegroups.com.

Reply via email to