github.com/s7techlab/cckit@v0.10.5/extensions/debug/state.go (about) 1 package debug 2 3 import ( 4 "fmt" 5 6 "github.com/s7techlab/cckit/state" 7 ) 8 9 // DeleteStateByPrefixes deletes from state entries with matching key prefix 10 // raw function, do not use State wrappers, like encryption 11 func DeleteStateByPrefixes(s state.State, prefixes []string) (map[string]uint32, error) { 12 prefixMatches := make(map[string]uint32) 13 14 for _, prefix := range prefixes { 15 16 keys, err := s.Keys(prefix) 17 if err != nil { 18 return nil, fmt.Errorf(`keys: %w`, err) 19 } 20 21 prefixMatches[prefix] = 0 22 for _, key := range keys { 23 if err = s.Delete(key); err != nil { 24 return nil, err 25 } 26 prefixMatches[prefix]++ 27 } 28 } 29 30 return prefixMatches, nil 31 }