【问题标题】:How to convert []*Cookie to []Cookie in Golang如何在 Golang 中将 []*Cookie 转换为 []Cookie
【发布时间】:2019-03-05 01:54:53
【问题描述】:

我有一个 []*Cookie 数组,但是如何获取 []Cookie 数组?我尝试使用 * 符号,但出现语法错误。

【问题讨论】:

标签: go


【解决方案1】:

Go 不提供从指向值的指针切片到值的切片的自动转换。

编写一个循环进行转换:

result := make([]Cookie, len(source))
for i := range result {
    result[i] = *source[i]
}

【讨论】:

    猜你喜欢
    • 2013-01-27
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2020-01-24
    • 2019-09-14
    相关资源
    最近更新 更多