package teamspeak // diffSlices 比较两个 OnlineClient 类型切片,以 DatabaseID 为基准,返回新增和删除的 []OnlineClient func diffSlices(old, new []Client) (added, removed []Client) { oldMap := make(map[int]Client) nowMap := make(map[int]Client) for _, item := range old { oldMap[item.DatabaseID] = item } for _, item := range new { nowMap[item.DatabaseID] = item } for id, item := range nowMap { if _, exists := oldMap[id]; !exists { added = append(added, item) } } for id, item := range oldMap { if _, exists := nowMap[id]; !exists { removed = append(removed, item) } } return added, removed }