go - Variable defined in Golang -
this question has answer here:
- assigning value in golang 3 answers
i create 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 fill tablevalue
of type *[]rows
. can please tell me example assigning values in tablevalue
.
slices reference type (it kind of pointer), don't need pointer slice (*[]rows
).
you can use slice of slices though tablevalue []rows
, rows
being slice of pointers 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.
Comments
Post a Comment