I have an interface{} that is similar like -
Rows interface{}
In the Rows interface i put ProductResponse struct.
type ProductResponse struct {
CompanyName string `json:"company_name"`
CompanyID uint `json:"company_id"`
CompanyProducts []*Products `json:"CompanyProducts"`
}
type Products struct {
Product_ID uint `json:"id"`
Product_Name string `json:"product_name"`
}
I want to access Product_Name value. How to access this. I can access outside values (CompanyName , CompanyID) by using "reflect" pkg.
value := reflect.ValueOf(response)
CompanyName := value.FieldByName("CompanyName").Interface().(string)
I am not able to access Products struct values. How to do that?
type Rows interface{ CompanyProducts() []*Products }, and then have yourProductResponsestruct satisfy that interface (and in the implementation, just return the struct field).