This question already has an answer here:
I create a var of type
var RespData []ResponseData
type ResponseData struct {
DataType string
Component string
ParameterName string
ParameterValue string
TableValue *[]Rows
}
type TabRow struct {
ColName string
ColValue string
ColDataType string
}
type Rows *[]TabRow
I want to fill TableValue
of type *[]Rows
. Can you please tell me with an example by assigning any values in the TableValue
.
</div>
Slices are reference type (it is already a kind of pointer), so you don't need a pointer to a slice (*[]Rows
).
You can use a slice of slices though TableValue []Rows
, with Rows
being a slice of pointers to TabRow
: Rows []*TabRow
.
tr11 := &TabRow{ColName: "cname11", ColValue: "cv11", ColDataType: "cd11"}
tr12 := &TabRow{ColName: "cname12", ColValue: "cv12", ColDataType: "cd12"}
row1 := Rows{tr11, tr12}
rd := &ResponseData{TableValue: []Rows{row1}}
fmt.Printf("%+v", rd )
See this example.