golang 的 rabbitmq 消费项目
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

71 lines
1.4 KiB

  1. package utils
  2. // ContainsString is 字符串是否包含在字符串切片里
  3. func ContainsString(array []string, val string) (index int) {
  4. index = -1
  5. for i := 0; i < len(array); i++ {
  6. if array[i] == val {
  7. index = i
  8. return
  9. }
  10. }
  11. return
  12. }
  13. //ArrayDiff 模拟PHP array_diff函数
  14. func ArrayDiff(array1 []interface{}, othersParams ...[]interface{}) ([]interface{}, error) {
  15. if len(array1) == 0 {
  16. return []interface{}{}, nil
  17. }
  18. if len(array1) > 0 && len(othersParams) == 0 {
  19. return array1, nil
  20. }
  21. var tmp = make(map[interface{}]int, len(array1))
  22. for _, v := range array1 {
  23. tmp[v] = 1
  24. }
  25. for _, param := range othersParams {
  26. for _, arg := range param {
  27. if tmp[arg] != 0 {
  28. tmp[arg]++
  29. }
  30. }
  31. }
  32. var res = make([]interface{}, 0, len(tmp))
  33. for k, v := range tmp {
  34. if v == 1 {
  35. res = append(res, k)
  36. }
  37. }
  38. return res, nil
  39. }
  40. //ArrayIntersect 模拟PHP array_intersect函数
  41. func ArrayIntersect(array1 []interface{}, othersParams ...[]interface{}) ([]interface{}, error) {
  42. if len(array1) == 0 {
  43. return []interface{}{}, nil
  44. }
  45. if len(array1) > 0 && len(othersParams) == 0 {
  46. return array1, nil
  47. }
  48. var tmp = make(map[interface{}]int, len(array1))
  49. for _, v := range array1 {
  50. tmp[v] = 1
  51. }
  52. for _, param := range othersParams {
  53. for _, arg := range param {
  54. if tmp[arg] != 0 {
  55. tmp[arg]++
  56. }
  57. }
  58. }
  59. var res = make([]interface{}, 0, len(tmp))
  60. for k, v := range tmp {
  61. if v > 1 {
  62. res = append(res, k)
  63. }
  64. }
  65. return res, nil
  66. }