(key string)
| 733 | } |
| 734 | |
| 735 | func (l *ListStructure) Size(key string) (string, error) { |
| 736 | Llen, err := l.LLen(key) |
| 737 | if err != nil { |
| 738 | return "", err |
| 739 | } |
| 740 | lRange, err := l.LRange(key, 0, Llen-1) |
| 741 | if err != nil { |
| 742 | return "", err |
| 743 | } |
| 744 | var sizeInBytes int |
| 745 | for _, v := range lRange { |
| 746 | toString, err := interfaceToString(v) |
| 747 | if err != nil { |
| 748 | return "", err |
| 749 | } |
| 750 | sizeInBytes += len(toString) |
| 751 | } |
| 752 | // Convert bytes to corresponding units (KB, MB...) |
| 753 | const ( |
| 754 | KB = 1 << 10 |
| 755 | MB = 1 << 20 |
| 756 | GB = 1 << 30 |
| 757 | ) |
| 758 | |
| 759 | var size string |
| 760 | switch { |
| 761 | case sizeInBytes < KB: |
| 762 | size = fmt.Sprintf("%dB", sizeInBytes) |
| 763 | case sizeInBytes < MB: |
| 764 | size = fmt.Sprintf("%.2fKB", float64(sizeInBytes)/KB) |
| 765 | case sizeInBytes < GB: |
| 766 | size = fmt.Sprintf("%.2fMB", float64(sizeInBytes)/MB) |
| 767 | } |
| 768 | |
| 769 | return size, nil |
| 770 | } |
nothing calls this directly
no test coverage detected