Jinnrry
Jinnrry

Reputation: 455

How to convert []*Cookie to []Cookie in Golang

I have a []*Cookie array, but how to get []Cookie array? I tried to use the * symbol but there was a syntax error.

Upvotes: 0

Views: 143

Answers (1)

Thundercat
Thundercat

Reputation: 121199

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]
}

Upvotes: 7

Related Questions