Skip to content

Commit 06a24e1

Browse files
committed
Remove tag from field map
1 parent a18c889 commit 06a24e1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

field_map.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ func (m *FieldMap) SetString(tag Tag, value string) *FieldMap {
227227
return m.SetBytes(tag, []byte(value))
228228
}
229229

230+
// Remove removes a tag from field map
231+
func (m *FieldMap) Remove(tag Tag) {
232+
m.rwLock.Lock()
233+
defer m.rwLock.Unlock()
234+
235+
delete(m.tagLookup, tag)
236+
}
237+
230238
// Clear purges all fields from field map.
231239
func (m *FieldMap) Clear() {
232240
m.rwLock.Lock()

field_map_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,15 @@ func TestFieldMap_CopyInto(t *testing.T) {
190190
assert.Nil(t, err)
191191
assert.Equal(t, "a", s)
192192
}
193+
194+
func TestFieldMap_Remove(t *testing.T) {
195+
var fMap FieldMap
196+
fMap.init()
197+
198+
fMap.SetField(1, FIXString("hello"))
199+
fMap.SetField(2, FIXString("world"))
200+
201+
fMap.Remove(1)
202+
assert.False(t, fMap.Has(1))
203+
assert.True(t, fMap.Has(2))
204+
}

0 commit comments

Comments
 (0)