aboutsummaryrefslogtreecommitdiff
path: root/handle_index.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-12 11:28:37 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-12 11:28:37 +0800
commit86f9d62c5ef3e61fdac9bda0a9920b8c1d9820fa (patch)
tree36c1ae664c6d3619c8cab9643732f87b7d1e9141 /handle_index.go
parent_footer.html: Fix upstream link (diff)
downloadforge-86f9d62c5ef3e61fdac9bda0a9920b8c1d9820fa.tar.gz
forge-86f9d62c5ef3e61fdac9bda0a9920b8c1d9820fa.tar.zst
forge-86f9d62c5ef3e61fdac9bda0a9920b8c1d9820fa.zip
handle_index: Query group names from database
Diffstat (limited to 'handle_index.go')
-rw-r--r--handle_index.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/handle_index.go b/handle_index.go
index 4301eed..c631546 100644
--- a/handle_index.go
+++ b/handle_index.go
@@ -2,22 +2,33 @@ package main
import (
"net/http"
- "os"
)
func handle_index(w http.ResponseWriter, r *http.Request) {
data := make(map[string]any)
- entries, err := os.ReadDir(config.Git.Root)
+ rows, err := database.Query(r.Context(), "SELECT name FROM groups")
if err != nil {
- _, _ = w.Write([]byte("Error listing groups: " + err.Error()))
+ _, _ = w.Write([]byte("Error querying groups: " + err.Error()))
return
}
+ defer rows.Close()
groups := []string{}
- for _, entry := range entries {
- groups = append(groups, entry.Name())
+ for rows.Next() {
+ var groupName string
+ if err := rows.Scan(&groupName); err != nil {
+ _, _ = w.Write([]byte("Error scanning group name: " + err.Error()))
+ return
+ }
+ groups = append(groups, groupName)
}
+
+ if err := rows.Err(); err != nil {
+ _, _ = w.Write([]byte("Error iterating over rows: " + err.Error()))
+ return
+ }
+
data["groups"] = groups
err = templates.ExecuteTemplate(w, "index", data)