2 comments

[ 39.1 ms ] story [ 46.6 ms ] thread
I've been using a pattern like this for my more complex initialisations:

s, i := make([]T, 0, 6), 0

s = append(s, 1, 2, 3)

//[1 2 3]

fmt.Println(s[i:])

i += 3

s = append(s, 4, 5, 6)

//[4 5 6]

fmt.Println(s[i:])

i += 3 // [etc...]

//[1 2 3 4 5 6]

fmt.Println(s[:])

You can easily make references to each chunk of the slice you append without much difficulty or any re-sizing (the first s[:] will remain a slice of the first 3 items).