aboutsummaryrefslogtreecommitdiff
path: root/http_handle_index.go
diff options
context:
space:
mode:
Diffstat (limited to 'http_handle_index.go')
-rw-r--r--http_handle_index.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/http_handle_index.go b/http_handle_index.go
new file mode 100644
index 0000000..bf36f98
--- /dev/null
+++ b/http_handle_index.go
@@ -0,0 +1,40 @@
+package main
+
+import (
+ "net/http"
+)
+
+func handle_index(w http.ResponseWriter, r *http.Request) {
+ data := make(map[string]any)
+ data["global"] = global_data
+
+ rows, err := database.Query(r.Context(), "SELECT name FROM groups")
+ if err != nil {
+ _, _ = w.Write([]byte("Error querying groups: " + err.Error()))
+ return
+ }
+ defer rows.Close()
+
+ groups := []string{}
+ 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)
+ if err != nil {
+ _, _ = w.Write([]byte("Error rendering template: " + err.Error()))
+ return
+ }
+}