aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-09 20:28:08 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-09 20:28:08 +0800
commit8af94f323d86c3cae992dc5ff4896bae52f208e8 (patch)
tree38bec3c6ea0950458d2840398ce285068bf99995
parentindex: Remove unnecessary newlines in td (diff)
downloadforge-8af94f323d86c3cae992dc5ff4896bae52f208e8.tar.gz
forge-8af94f323d86c3cae992dc5ff4896bae52f208e8.tar.zst
forge-8af94f323d86c3cae992dc5ff4896bae52f208e8.zip
index: Humanize allocated size
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--http_handle_index.go4
-rw-r--r--templates/index.tmpl2
4 files changed, 7 insertions, 2 deletions
diff --git a/go.mod b/go.mod
index 708f80d..950a5a9 100644
--- a/go.mod
+++ b/go.mod
@@ -25,6 +25,7 @@ require (
github.com/cloudflare/circl v1.6.0 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
+ github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
diff --git a/go.sum b/go.sum
index a5b5cbb..fe90c8d 100644
--- a/go.sum
+++ b/go.sum
@@ -28,6 +28,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
+github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
+github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o=
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
diff --git a/http_handle_index.go b/http_handle_index.go
index 623c619..144e9ab 100644
--- a/http_handle_index.go
+++ b/http_handle_index.go
@@ -6,6 +6,8 @@ package main
import (
"net/http"
"runtime"
+
+ "github.com/dustin/go-humanize"
)
func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) {
@@ -22,6 +24,6 @@ func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any)
// Memory currently allocated
memstats := runtime.MemStats{}
runtime.ReadMemStats(&memstats)
- params["mem"] = memstats.Alloc
+ params["mem"] = humanize.IBytes(memstats.Alloc)
render_template(w, "index", params)
}
diff --git a/templates/index.tmpl b/templates/index.tmpl
index c767adb..7c2e8fc 100644
--- a/templates/index.tmpl
+++ b/templates/index.tmpl
@@ -55,7 +55,7 @@
</tr>
<tr>
<th scope="row">Memory usage</th>
- <td>Allocated {{ .mem }} bytes <a href="/:/gc/" class="btn btn-danger">Run the garbage collector</a></td>
+ <td>Allocated {{ .mem }} <a href="/:/gc/" class="btn btn-danger">Run the garbage collector</a></td>
</tr>
</tbody>
</table>