mirror of
				https://github.com/gin-gonic/gin.git
				synced 2025-11-04 17:22:12 +08:00 
			
		
		
		
	feat(context): implemented Delete method
Co-authored-by: suhan <s.bangera@castsoftware.com>
This commit is contained in:
		
							parent
							
								
									c221133ee8
								
							
						
					
					
						commit
						38e7651192
					
				
							
								
								
									
										10
									
								
								context.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								context.go
									
									
									
									
									
								
							@ -465,6 +465,16 @@ func (c *Context) GetStringMapStringSlice(key any) (smss map[string][]string) {
 | 
				
			|||||||
	return getTyped[map[string][]string](c, key)
 | 
						return getTyped[map[string][]string](c, key)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Delete deletes the key from the Context's Key map, if it exists.
 | 
				
			||||||
 | 
					// This operation is safe to be used by concurrent go-routines
 | 
				
			||||||
 | 
					func (c *Context) Delete(key any) {
 | 
				
			||||||
 | 
						c.mu.Lock()
 | 
				
			||||||
 | 
						defer c.mu.Unlock()
 | 
				
			||||||
 | 
						if c.Keys != nil {
 | 
				
			||||||
 | 
							delete(c.Keys, key)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/************************************/
 | 
					/************************************/
 | 
				
			||||||
/************ INPUT DATA ************/
 | 
					/************ INPUT DATA ************/
 | 
				
			||||||
/************************************/
 | 
					/************************************/
 | 
				
			||||||
 | 
				
			|||||||
@ -404,6 +404,19 @@ func TestContextSetGetBool(t *testing.T) {
 | 
				
			|||||||
	assert.True(t, c.GetBool("bool"))
 | 
						assert.True(t, c.GetBool("bool"))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSetGetDelete(t *testing.T) {
 | 
				
			||||||
 | 
						c, _ := CreateTestContext(httptest.NewRecorder())
 | 
				
			||||||
 | 
						key := "example-key"
 | 
				
			||||||
 | 
						value := "example-value"
 | 
				
			||||||
 | 
						c.Set(key, value)
 | 
				
			||||||
 | 
						val, exists := c.Get(key)
 | 
				
			||||||
 | 
						assert.True(t, exists)
 | 
				
			||||||
 | 
						assert.Equal(t, val, value)
 | 
				
			||||||
 | 
						c.Delete(key)
 | 
				
			||||||
 | 
						_, exists = c.Get(key)
 | 
				
			||||||
 | 
						assert.False(t, exists)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestContextGetInt(t *testing.T) {
 | 
					func TestContextGetInt(t *testing.T) {
 | 
				
			||||||
	c, _ := CreateTestContext(httptest.NewRecorder())
 | 
						c, _ := CreateTestContext(httptest.NewRecorder())
 | 
				
			||||||
	c.Set("int", 1)
 | 
						c.Set("int", 1)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user