added cache remove functions.
This commit is contained in:
		
							
								
								
									
										64
									
								
								client.go
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								client.go
									
									
									
									
									
								
							@@ -230,3 +230,67 @@ func (c *Cache) GetMember(id string) *Member {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return &Member{}
 | 
						return &Member{}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Remove a channel from cache by Id.
 | 
				
			||||||
 | 
					// Will not delete the channel, just deletes the channel from cache.
 | 
				
			||||||
 | 
					// Will change the entire channel cache order!
 | 
				
			||||||
 | 
					func (c *Cache) RemoveChannel(id string) error {
 | 
				
			||||||
 | 
						for i, v := range c.Channels {
 | 
				
			||||||
 | 
							if v.Id == id {
 | 
				
			||||||
 | 
								c.Channels[i] = c.Channels[len(c.Channels)-1]
 | 
				
			||||||
 | 
								c.Channels = c.Channels[:len(c.Channels)-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return fmt.Errorf("channel not found")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Remove a server from cache by Id.
 | 
				
			||||||
 | 
					// Will not delete the server, just deletes the server from cache.
 | 
				
			||||||
 | 
					// Will change the entire server cache order!
 | 
				
			||||||
 | 
					func (c *Cache) RemoveServer(id string) error {
 | 
				
			||||||
 | 
						for i, v := range c.Servers {
 | 
				
			||||||
 | 
							if v.Id == id {
 | 
				
			||||||
 | 
								c.Servers[i] = c.Servers[len(c.Servers)-1]
 | 
				
			||||||
 | 
								c.Servers = c.Servers[:len(c.Servers)-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return fmt.Errorf("server not found")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Remove an user from cache by Id.
 | 
				
			||||||
 | 
					// Will not delete the user, just deletes the user from cache.
 | 
				
			||||||
 | 
					// Will change the entire user cache order!
 | 
				
			||||||
 | 
					func (c *Cache) RemoveUser(id string) error {
 | 
				
			||||||
 | 
						for i, v := range c.Users {
 | 
				
			||||||
 | 
							if v.Id == id {
 | 
				
			||||||
 | 
								c.Users[i] = c.Users[len(c.Users)-1]
 | 
				
			||||||
 | 
								c.Users = c.Users[:len(c.Users)-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return fmt.Errorf("user not found")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Remove a member from cache by Id.
 | 
				
			||||||
 | 
					// Will not delete the member, just deletes the member from cache.
 | 
				
			||||||
 | 
					// Will change the entire member cache order!
 | 
				
			||||||
 | 
					func (c *Cache) RemoveMember(id string) error {
 | 
				
			||||||
 | 
						for i, v := range c.Members {
 | 
				
			||||||
 | 
							if v.Informations.UserId == id {
 | 
				
			||||||
 | 
								c.Members[i] = c.Members[len(c.Members)-1]
 | 
				
			||||||
 | 
								c.Members = c.Members[:len(c.Members)-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return fmt.Errorf("member not found")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user