Recursive Struct

type Footer struct {
ID uint json:"id,omitempty"
Name string json:"name,omitempty"
Title string json:"title,omitempty"
Slug string json:"slug,omitempty"
URL string json:"url,omitempty"
Position unit json:"position,omitempty"
ParentID string json:"parent_id,omitempty"
Child []Footer json:"list,omitempty"
}

i am working on endpoint to show all data from Footer. in my kind-of getAllFooter endpoint, firstly i query the row based on parent_id number that is 0. As for the Child thing, i did a query based on ID of first query … from the same table. so my footer table provides data that shows wether a certain row is a parent or not. i am doing fine to show all parent but the child dont show up.

i am new in golang, and is in need to learn much. so, if everyone can give me an explanation.

here is my json data resp

“data”: [
{
“id”: 1,
“name”: “Term and Policies”,
“position”: “1”
},
{
“id”: 2,
“name”: “Customer Service”,
“position”: “2”
}
]

it dont even show the Child things. i dont understand :frowning:

Hi are you sure the Child field of the struct isn’t empty? Use a debugger or print the struct before converting it to json.

fmt.Printf("%#v", myFooter)
1 Like