I have a []*Cookie array, but how to get []Cookie array? I tried to use the * symbol but there was a syntax error.
Asked
Active
Viewed 118 times
0
-
9Why do you need to do the conversion? – peterSO Mar 05 '19 at 02:16
-
2Duplicate: https://stackoverflow.com/q/48459846/13860 – Jonathan Hall Mar 05 '19 at 06:55
1 Answers
7
Go does not provide an automatic conversion from slice of pointers to values to a slice of values.
Write a loop to do the conversion:
result := make([]Cookie, len(source))
for i := range result {
result[i] = *source[i]
}

Charlie Tumahai
- 113,709
- 12
- 249
- 242