golang的數組與map缺乏像php同樣不少的系統api的支持,使得諸如像獲取map中全部key或者打亂數組等這些操做都須要本身寫一個api。而此時collection應運而生,collection是一個數據結構能夠很輕易的跟map和slice自由轉換。collection幾乎包括了你開發所須要的各類api操做,php有的都會有。php
對map數組的支持使得你能夠對數據庫查來的數據進行諸如where查詢,篩選乃至於修改等操做。極大的提高了你的golang開發效率。並且collection致力於提供優雅的便捷的且健壯api,使得你開發的代碼十分簡潔易於維護。git
項目地址:https://github.com/chenhg5/co...
文檔地址:https://godoc.org/github.com/...github
歡迎star,歡迎prgolang
獲取map的全部key數據庫
a := map[string]interface{}{ "name": "mike", "sex": 1, } fmt.Println(Collect(a).Keys().ToStringArray()) // Output: [name sex]
數組排序api
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]
更多例子在這裏數據結構