Browse Source

Add options.DeleteByPrefix

DarthSim 1 week ago
parent
commit
ffd1f5b13d
1 changed files with 9 additions and 0 deletions
  1. 9 0
      options/options.go

+ 9 - 0
options/options.go

@@ -145,6 +145,15 @@ func (o *Options) Delete(key string) {
 	delete(o.m, key)
 	delete(o.m, key)
 }
 }
 
 
+// DeleteByPrefix removes all options that start with the given prefix.
+func (o *Options) DeleteByPrefix(prefix string) {
+	for k := range o.m {
+		if strings.HasPrefix(k, prefix) {
+			delete(o.m, k)
+		}
+	}
+}
+
 // DeleteFromChildren removes an option by its key from the child Options if any.
 // DeleteFromChildren removes an option by its key from the child Options if any.
 func (o *Options) DeleteFromChildren(key string) {
 func (o *Options) DeleteFromChildren(key string) {
 	if o.child == nil {
 	if o.child == nil {