Lindenii Project Forge
Login
Commit info
IDc8f7040fe57d5f16a0a54c2cd85424511d537ad3
AuthorRunxi Yu<me@runxiyu.org>
Author dateSun, 09 Mar 2025 16:33:51 +0800
CommitterRunxi Yu<me@runxiyu.org>
Committer dateSun, 09 Mar 2025 16:33:51 +0800
Actions
Get patch
index: Show allocated bytes
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>

package main

import (
	"net/http"
	"runtime"
)

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"] = memstats.Alloc
	render_template(w, "index", params)
}
{{/*
	SPDX-License-Identifier: AGPL-3.0-only
	SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
*/}}
{{- define "index" -}}
<!DOCTYPE html>
<html lang="en">
	<head>
		{{- template "head_common" . -}}
		<title>Index &ndash; {{ .global.forge_title -}}</title>
	</head>
	<body class="index">
		{{- template "header" . -}}
		<div class="padding-wrapper">
		<table class="wide">
			<thead>
				<tr>
					<th colspan="2" class="title-row">Groups</th>
				</tr>
				<tr>
					<th scope="col">Name</th>
					<th scope="col">Description</th>
				</tr>
			</thead>
			<tbody>
				{{- range .groups -}}
					<tr>
						<td>
							<a href="{{- .Name | path_escape -}}/">{{- .Name -}}</a>
						</td>
						<td>
							{{- .Description -}}
						</td>
					</tr>
				{{- end -}}
			</tbody>
		</table>
		<div class="padding-wrapper">
			<table class="wide">
				<thead>
					<tr>
						<th colspan="2" class="title-row">
							Info
						</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<th scope="row">SSH public key</th>
						<td><code>{{- .global.server_public_key_string -}}</code></td>
					</tr>
					<tr>
						<th scope="row">SSH fingerprint</th>
						<td><code>{{- .global.server_public_key_fingerprint -}}</code></td>
					</tr>
					<tr>
						<th scope="row">Memory usage</th>
						<td>
							Allocated {{ .mem }} bytes <a href="/:/gc/" class="btn btn-danger">Collect garbage</a>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="padding-wrapper">
			<a href="/:/gc" class="btn btn-danger">Run the garbage collector</a>
		</div>
		<footer>
			{{- template "footer" . -}}
		</footer>
	</body>
</html>
{{- end -}}