golang的数组与map缺少像php一样很多的系统api的支持,使得诸如像获取map中所有key或者打乱数组等这些操作都需要自己写一个api。而此时collection应运而生,collection是一个数据结构可以很轻易的跟map和slice自由转换。collection几乎包括了你开发所需要的各种api操作,php有的都会有。

对map数组的支持使得你可以对数据库查来的数据进行诸如where查询,筛选乃至于修改等操作。极大的提升了你的golang开发效率。而且collection致力于提供优雅的便捷的且健壮api,使得你开发的代码十分简洁易于维护。

项目地址:https://github.com/chenhg5/co...
文档地址:https://godoc.org/github.com/...

欢迎star,欢迎pr

使用例子


a := map[string]interface{}{
        "name": "mike",
        "sex":  1,
    }

fmt.Println(Collect(a).Keys().ToStringArray())

// Output: [name sex]

a := []int{4, 5, 2, 3, 6, 7}

fmt.Println(Collect(a).Sort().ToIntArray())

// Output: [2 3 4 5 6 7]

a := []int{4, 5, 2, 3, 6, 7}

fmt.Println(Collect(a). Shuffle().ToIntArray())

// Output: [3 2 5 4 6 7]