I'm genuinely confused about what you are trying to accomplish. In the code 
you posted you don't iterate over anything. Also, the variables d and f in 
your code are completely redundant. You could remove the 4 lines and simply 
` fmt.Println("Output", pslice )`, and get the same result. So, perhaps you 
could be more precise about what you have and what you want to do with it. 
For example, do you have an interface{} that you *know *contains a 
[]product, and want to actually iterate over all the product items? or 
something else?

On Friday, December 11, 2020 at 10:20:21 AM UTC-5 Salim Aft wrote:

> Could someone help,
>  I am trying to itreate over  an interface and fetch the "id" and "name" 
> in below code,
> is there a better way to do this.
>
> package main
>
> import (
>     "fmt"
> )
>
>  type product struct {
>      id int
>      name string
>  }
> func main(){
>     fmt.Println("Hello ALLTEST")
>     p := product{id : 12, name:"apple"}
>     c := product{id : 13, name:"samsung"}
>     var pslice []product    
>     pslice = append(pslice, p)
>     pslice = append(pslice, c)
>     d := map[string]interface{}{
>         "allproducts" : pslice,
>     }
>     f:= d["allproducts"]
>     fmt.Println("Output", f)
>

-- 
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/32af3985-0099-41fe-bbc9-810c86e9cfd3n%40googlegroups.com.

Reply via email to