golang 的 rabbitmq 消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 lines
1.2 KiB

  1. package utils
  2. // MapStringKeys 取出map的key
  3. func MapStringKeys(collection *map[string]struct{}) []interface{} {
  4. result := make([]interface{}, 0, len(*collection))
  5. for key := range *collection {
  6. result = append(result, key)
  7. }
  8. return result
  9. }
  10. // GetOneKeyOfMapString 取出Map的一个key
  11. func GetOneKeyOfMapString(collection map[string]string) string {
  12. for k := range collection {
  13. return k
  14. }
  15. return ""
  16. }
  17. // sources源数组,num拆分份数,size每份的大小
  18. func SplitArray(sources []string, num, pageSize int64) [][]string {
  19. max := int64(len(sources))
  20. if max < num {
  21. return nil
  22. }
  23. var segmens = make([][]string, 0)
  24. quantity := pageSize
  25. end := int64(0)
  26. for i := int64(1); i <= num; i++ {
  27. qu := i * quantity
  28. if i != num {
  29. segmens = append(segmens, sources[i-1+end:qu])
  30. } else {
  31. segmens = append(segmens, sources[i-1+end:])
  32. }
  33. end = qu - i
  34. }
  35. return segmens
  36. }
  37. // sourceslen源数组长度,pageSize页数据量
  38. // 获取拆分份数
  39. func SplitArrayCnt(sourceslen, pageSize int) int {
  40. if sourceslen < pageSize {
  41. return 1
  42. }
  43. s := sourceslen / pageSize
  44. y := sourceslen % pageSize
  45. if y > 0 {
  46. return s + 1
  47. } else {
  48. return s
  49. }
  50. }