aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbingoohuang <bingoo.huang@gmail.com>2021-07-06 15:20:18 +0800
committerbingoohuang <bingoo.huang@gmail.com>2021-07-06 15:20:18 +0800
commited57a55eaec2318bf21693582105660d7612118b (patch)
tree074de0329a1e16c149d828b0fe6e4227c682b3c0
parent44a2538f6772adddf6c47abe7cf6288718a80165 (diff)
downloadseaweedfs-ed57a55eaec2318bf21693582105660d7612118b.tar.xz
seaweedfs-ed57a55eaec2318bf21693582105660d7612118b.zip
show RemoteVolumes/EcVolumes only if it is not empty
-rw-r--r--weed/server/volume_server_ui/templates.go1
-rw-r--r--weed/server/volume_server_ui/volume.html5
-rw-r--r--weed/util/reflect.go40
3 files changed, 45 insertions, 1 deletions
diff --git a/weed/server/volume_server_ui/templates.go b/weed/server/volume_server_ui/templates.go
index 8034d8218..d85eb247a 100644
--- a/weed/server/volume_server_ui/templates.go
+++ b/weed/server/volume_server_ui/templates.go
@@ -25,6 +25,7 @@ var funcMap = template.FuncMap{
"join": join,
"bytesToHumanReadable": util.BytesToHumanReadable,
"percentFrom": percentFrom,
+ "isNotEmpty": util.IsNotEmpty,
}
//go:embed volume.html
diff --git a/weed/server/volume_server_ui/volume.html b/weed/server/volume_server_ui/volume.html
index 973b0bfbe..91809beb0 100644
--- a/weed/server/volume_server_ui/volume.html
+++ b/weed/server/volume_server_ui/volume.html
@@ -133,6 +133,7 @@
</table>
</div>
+ {{ if isNotEmpty .RemoteVolumes }}
<div class="row">
<h2>Remote Volumes</h2>
<table class="table table-striped">
@@ -162,7 +163,9 @@
</tbody>
</table>
</div>
+ {{ end }}
+ {{ if isNotEmpty .EcVolumes }}
<div class="row">
<h2>Erasure Coding Shards</h2>
<table class="table table-striped">
@@ -188,7 +191,7 @@
</tbody>
</table>
</div>
-
+ {{ end }}
</div>
</body>
</html>
diff --git a/weed/util/reflect.go b/weed/util/reflect.go
new file mode 100644
index 000000000..77186f67e
--- /dev/null
+++ b/weed/util/reflect.go
@@ -0,0 +1,40 @@
+package util
+
+import "reflect"
+
+// IsNotEmpty returns true if the given value is not zero or empty.
+func IsNotEmpty(given interface{}) bool {
+ return !IsEmpty(given)
+}
+
+// IsEmpty returns true if the given value has the zero value for its type.
+func IsEmpty(given interface{}) bool {
+ g := reflect.ValueOf(given)
+ if !g.IsValid() {
+ return true
+ }
+
+ if g.Kind() == reflect.Ptr {
+ g = g.Elem()
+ }
+
+ // Basically adapted from text/template.isTrue
+ switch g.Kind() {
+ case reflect.Array, reflect.Slice, reflect.Map, reflect.String:
+ return g.Len() == 0
+ case reflect.Bool:
+ return !g.Bool()
+ case reflect.Complex64, reflect.Complex128:
+ return g.Complex() == 0
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+ return g.Int() == 0
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
+ return g.Uint() == 0
+ case reflect.Float32, reflect.Float64:
+ return g.Float() == 0
+ case reflect.Struct:
+ return g.IsZero()
+ default:
+ return g.IsNil()
+ }
+}