Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode

 Conflicts:
	cmd/api/main.go
	go.mod
	internal/push/fcm/push.go
	internal/push/getui/push.go
	internal/push/logic/init.go
	internal/push/logic/push_to_client.go
	internal/push/push_rpc_server.go
	internal/rpc/conversation/conversaion.go
	pkg/common/db/controller/group.go
	pkg/proto/push/push.pb.go
This commit is contained in:
wangchuxiao
2023-02-22 19:52:53 +08:00
134 changed files with 3751 additions and 3309 deletions
+33 -1
View File
@@ -5,6 +5,38 @@ import (
"sort"
)
// SliceSub a中存在,b中不存在 (a-b)
func SliceSub[E comparable](a, b []E) []E {
k := make(map[E]struct{})
for i := 0; i < len(b); i++ {
k[b[i]] = struct{}{}
}
t := make(map[E]struct{})
rs := make([]E, 0, len(a))
for i := 0; i < len(a); i++ {
e := a[i]
if _, ok := t[e]; ok {
continue
}
if _, ok := k[e]; ok {
continue
}
rs = append(rs, e)
t[e] = struct{}{}
}
return rs
}
// SliceSubAny a中存在,b中不存在 (a-b)
func SliceSubAny[E comparable, T any](a []E, b []T, fn func(t T) E) []E {
return SliceSub(a, Slice(b, fn))
}
// SliceAnySub a中存在,b中不存在 (a-b) fn 返回的是uuid
func SliceAnySub[E any, T comparable](a, b []E, fn func(t E) T) []E {
panic("todo")
}
// DistinctAny 去重
func DistinctAny[E any, K comparable](es []E, fn func(e E) K) []E {
v := make([]E, 0, len(es))
@@ -159,7 +191,7 @@ func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T {
func Slice[E any, T any](es []E, fn func(e E) T) []T {
v := make([]T, len(es))
for i := 0; i < len(es); i++ {
v = append(v, fn(es[i]))
v[i] = fn(es[i])
}
return v
}