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: []string{"name", "sex"}
a := []int{4, 5, 2, 3, 6, 7}
fmt.Println(Collect(a).Sort().ToIntArray())
// Output: []int{2, 3, 4, 5, 6, 7}
a := []int{4, 5, 2, 3, 6, 7}
fmt.Println(Collect(a). Shuffle().ToIntArray())
// Output: []int{ 3, 2, 5, 4, 6, 7}