Greetings:
Having issues creating var with an existing instance of structs.
The code snippet is below:
import (
“fmt”
“reflect”
)
type Product struct {
Name string
Price string
}
func main() {
p := Product{Name: “Hello”}
fmt.Println(p)
var data []p // This is causing issues
fmt.Println(data)
}
Can someone help me with this as I am stuck up? Need to create an Array of type Product. I do not want to use var data []Product directly as I have multiple structs and use an instance of structs.
Thanks, Sean!
The requirement is to create an array with an existing instance of Product that is p instead of using struct (Product) directly.
I could have done var data []Product and that would be fine. But, I need to do something like var data []p
I would pass an instance of Product and/or other structs using a function as an interface and do the rest of the coding.