drr25281 2019-03-05 01:54
浏览 71
已采纳

如何在Golang中将[] * Cookie转换为[] Cookie

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

  • 写回答

1条回答 默认 最新

  • douxunnian0423 2019-03-05 02:12
    关注

    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]
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?