Lindenii Project Forge
Login

/http_handle_index.go (raw)

// 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 handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) {
	var err error
	var groups []name_desc_t

	groups, err = query_name_desc_list(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)
	render_template(w, "index", params)
}