I'm trying to add value to a slice of struct, I have the following struct:
type RelatedSearchItem struct {
Title string `json:"title"`
Navigation string `json:"url"`
}
Now I create a slice of this struct :
relatedSearchItem := []models.RelatedSearchItem{}
And finally I add data to his fields :
for i := 0; i < len(questions); i++ {
relatedSearchItem[i].Title = questions[i]
relatedSearchItem[i].Navigation = URL[i]
}
But when I do this I'm out of the range of the slice so my app crash, how can I add data to this slice of struct and without a fixed length ?
I immediately think about append
but here I'm not adding a slice to another I just want to build it with my data.