All entries in slice end up identical after copying from another slice
Two facts to consider:
-
id
is of type UUID, which is[16]byte
. - Loop variables a overwritten at each iteration
Thus, there is only one instance of id
is allocated and shared between all iterations of the for loop. Since id
is an array (not a slice), contents of each UUID are copied to id
. All the slices id[:]
, thus, point to the same shared underlying byte array, which, when the loop ends, contains the latest contents of id
.
To fix:
idBytes[i] = ids[i][:]
which will create separate slices for each UUID.