Re: [go-nuts] how to declare type as interface{}

2020-09-03 Thread Harald Weidner
Hello,

> but this doesn't work:
>
> if err := json.NewDecoder(resp.Body).Decode({}{}); err != nil {
>  t.Fatal(err)
> }

You can use new(interface{}).

See https://play.golang.org/p/s85MwlDygBG

Harald

-- 
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/20200903222503.GA4288%40hweidner.de.


Re: [go-nuts] how to declare type as interface{}

2020-09-03 Thread Brian Candler
You can't take the address of an arbitrary value or expression, although 
you can for composite literals which is why {}{} is OK.
https://golang.org/ref/spec#Address_operators

-- 
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/48280a9d-78ef-4d91-8a42-198b63b035bdo%40googlegroups.com.


Re: [go-nuts] how to declare type as interface{}

2020-09-03 Thread 'Axel Wagner' via golang-nuts
What's wrong with the first one?
The second one doesn't work because there are not interface composite
literals. So you need to actually have an interface{} variable to take the
address of.
The third one seems to work just fine: https://play.golang.org/p/zn2mL69VzPo

On Thu, Sep 3, 2020 at 10:32 PM Alexander Mills 
wrote:

> This works:
>
> var z interface{}
> if err := json.NewDecoder(resp.Body).Decode(); err != nil {
>  t.Fatal(err)
> }
>
> but this doesn't work:
>
> if err := json.NewDecoder(resp.Body).Decode({}{}); err != nil {
>  t.Fatal(err)
> }
>
> and this doesn't work:
>
> if err := json.NewDecoder(resp.Body).Decode({}{}); err != nil {
>  t.Fatal(err)
> }
>
>
> my goal is to unmarshal to an anonymous variable and discard it, as part
> of a test. Is there a way to do this?
>
> --
> 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/8f58f470-8055-49bc-a248-92a496473f8bn%40googlegroups.com
> 
> .
>

-- 
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/CAEkBMfHrVdqn87qWHuxWnyBD%3Dn8y0qr8WcQdjH6RG5zcv-OAtA%40mail.gmail.com.


[go-nuts] how to declare type as interface{}

2020-09-03 Thread Alexander Mills
This works:

var z interface{}
if err := json.NewDecoder(resp.Body).Decode(); err != nil {
 t.Fatal(err)
}

but this doesn't work:

if err := json.NewDecoder(resp.Body).Decode({}{}); err != nil {
 t.Fatal(err)
}

and this doesn't work:

if err := json.NewDecoder(resp.Body).Decode({}{}); err != nil {
 t.Fatal(err)
}


my goal is to unmarshal to an anonymous variable and discard it, as part of 
a test. Is there a way to do this?

-- 
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/8f58f470-8055-49bc-a248-92a496473f8bn%40googlegroups.com.