package utils // MapStringKeys 取出map的key func MapStringKeys(collection *map[string]struct{}) []interface{} { result := make([]interface{}, 0, len(*collection)) for key := range *collection { result = append(result, key) } return result } // GetOneKeyOfMapString 取出Map的一个key func GetOneKeyOfMapString(collection map[string]string) string { for k := range collection { return k } return "" } // sources源数组,num拆分份数,size每份的大小 func SplitArray(sources []string, num, pageSize int64) [][]string { max := int64(len(sources)) if max < num { return nil } var segmens = make([][]string, 0) quantity := pageSize end := int64(0) for i := int64(1); i <= num; i++ { qu := i * quantity if i != num { segmens = append(segmens, sources[i-1+end:qu]) } else { segmens = append(segmens, sources[i-1+end:]) } end = qu - i } return segmens } // sourceslen源数组长度,pageSize页数据量 // 获取拆分份数 func SplitArrayCnt(sourceslen, pageSize int) int { if sourceslen < pageSize { return 1 } s := sourceslen / pageSize y := sourceslen % pageSize if y > 0 { return s + 1 } else { return s } }