Break KV portion of enchance into separate func

This commit is contained in:
Joel Watson 2020-11-10 10:29:49 -06:00
parent 354ff0a0d1
commit 0553532e00
1 changed files with 44 additions and 35 deletions

View File

@ -258,12 +258,32 @@ func (c *cmd) enhance(file io.Reader) (SnapshotInfo, error) {
info.TotalSize = cr.read
info.Stats[msg] = s
c.kvEnhance(s.Name, val, size, &info)
return nil
}
if err := fsm.ReadSnapshot(cr, handler); err != nil {
return info, err
}
return info, nil
}
func (c *cmd) kvEnhance(keyType string, val interface{}, size int, info *SnapshotInfo) {
if c.detailed {
if s.Name == "KVS" {
switch val := val.(type) {
case map[string]interface{}:
for k, v := range val {
if k == "Key" {
if keyType != "KVS" {
return
}
// have to coerce this into a usable type here or this won't work
keyVal := val.(map[string]interface{})
for k, v := range keyVal {
// we only care about the entry on the key specifically
// related to the key name, so skip all others
if k != "Key" {
continue
}
// check for whether a filter is specified. if it is, skip
// any keys that don't match.
if len(c.filter) > 0 && !strings.HasPrefix(v.(string), c.filter) {
@ -290,17 +310,6 @@ func (c *cmd) enhance(file io.Reader) (SnapshotInfo, error) {
info.StatsKV[prefix] = kvs
}
}
}
}
}
return nil
}
if err := fsm.ReadSnapshot(cr, handler); err != nil {
return info, err
}
return info, nil
}
func (c *cmd) Synopsis() string {