File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -465,6 +465,16 @@ func (c *Context) GetStringMapStringSlice(key any) (smss map[string][]string) {
465465 return getTyped [map [string ][]string ](c , key )
466466}
467467
468+ // Delete deletes the key from the Context's Key map, if it exists.
469+ // This operation is safe to be used by concurrent go-routines
470+ func (c * Context ) Delete (key any ) {
471+ c .mu .Lock ()
472+ defer c .mu .Unlock ()
473+ if c .Keys != nil {
474+ delete (c .Keys , key )
475+ }
476+ }
477+
468478/************************************/
469479/************ INPUT DATA ************/
470480/************************************/
Original file line number Diff line number Diff line change @@ -404,6 +404,19 @@ func TestContextSetGetBool(t *testing.T) {
404404 assert .True (t , c .GetBool ("bool" ))
405405}
406406
407+ func TestSetGetDelete (t * testing.T ) {
408+ c , _ := CreateTestContext (httptest .NewRecorder ())
409+ key := "example-key"
410+ value := "example-value"
411+ c .Set (key , value )
412+ val , exists := c .Get (key )
413+ assert .True (t , exists )
414+ assert .Equal (t , val , value )
415+ c .Delete (key )
416+ _ , exists = c .Get (key )
417+ assert .False (t , exists )
418+ }
419+
407420func TestContextGetInt (t * testing.T ) {
408421 c , _ := CreateTestContext (httptest .NewRecorder ())
409422 c .Set ("int" , 1 )
You can’t perform that action at this time.
0 commit comments