diff options
| author | bingoohuang <bingoo.huang@gmail.com> | 2020-05-29 15:37:58 +0800 |
|---|---|---|
| committer | bingoohuang <bingoo.huang@gmail.com> | 2020-05-29 15:37:58 +0800 |
| commit | 1a642b98769ea604dfb74fa4d875bf42c24fda9f (patch) | |
| tree | 115044480b7c8c726e0e5d0bb2f8716952ac74e9 /weed/util/inits.go | |
| parent | b4e93b639d95da4954052c583e2368baef2992c7 (diff) | |
| download | seaweedfs-1a642b98769ea604dfb74fa4d875bf42c24fda9f.tar.xz seaweedfs-1a642b98769ea604dfb74fa4d875bf42c24fda9f.zip | |
add Volume Ids column only for max 100 volumes for convenience in the master ui.
Diffstat (limited to 'weed/util/inits.go')
| -rw-r--r-- | weed/util/inits.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/weed/util/inits.go b/weed/util/inits.go new file mode 100644 index 000000000..dfbf9da5f --- /dev/null +++ b/weed/util/inits.go @@ -0,0 +1,43 @@ +package util + +import ( + "fmt" + "sort" +) + +// HumanReadableInts joins a serials of inits into a smart one like 1-3 5 7-10 for human readable. +func HumanReadableInts(ids ...int) string { + sort.Ints(ids) + + s := "" + start := 0 + last := 0 + + for i, v := range ids { + if i == 0 { + start = v + last = v + s = fmt.Sprintf("%d", v) + continue + } + + if last+1 == v { + last = v + continue + } + + if last > start { + s += fmt.Sprintf("-%d", last) + } + + s += fmt.Sprintf(" %d", v) + start = v + last = v + } + + if last != start { + s += fmt.Sprintf("-%d", last) + } + + return s +} |
