aboutsummaryrefslogtreecommitdiff
path: root/http_handle_index.go
blob: 2fc99a68c4543751e2214259e8177f40e30383da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>

package main

import (
	"net/http"
	"runtime"

	"github.com/dustin/go-humanize"
)

func httpHandleIndex(w http.ResponseWriter, r *http.Request, params map[string]any) {
	var err error
	var groups []nameDesc

	groups, err = queryNameDesc(r.Context(), "SELECT name, COALESCE(description, '') FROM groups WHERE parent_group IS NULL")
	if err != nil {
		http.Error(w, "Error querying groups: "+err.Error(), http.StatusInternalServerError)
		return
	}
	params["groups"] = groups

	// Memory currently allocated
	memstats := runtime.MemStats{}
	runtime.ReadMemStats(&memstats)
	params["mem"] = humanize.IBytes(memstats.Alloc)
	renderTemplate(w, "index", params)
}