diff options
Diffstat (limited to '')
-rw-r--r-- | http_handle_index.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/http_handle_index.go b/http_handle_index.go index 8066a03..e36332d 100644 --- a/http_handle_index.go +++ b/http_handle_index.go @@ -5,25 +5,31 @@ import ( ) func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) { - rows, err := database.Query(r.Context(), "SELECT name FROM groups") + rows, err := database.Query(r.Context(), "SELECT name, COALESCE(description, '') FROM groups") if err != nil { - http.Error(w, "Error querying groups: : "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error querying groups: "+err.Error(), http.StatusInternalServerError) return } defer rows.Close() - groups := []string{} + groups := []struct { + Name string + Description string + }{} for rows.Next() { - var groupName string - if err := rows.Scan(&groupName); err != nil { - http.Error(w, "Error scanning group name: : "+err.Error(), http.StatusInternalServerError) + var groupName, groupDescription string + if err := rows.Scan(&groupName, &groupDescription); err != nil { + http.Error(w, "Error scanning group: "+err.Error(), http.StatusInternalServerError) return } - groups = append(groups, groupName) + groups = append(groups, struct { + Name string + Description string + }{groupName, groupDescription}) } if err := rows.Err(); err != nil { - http.Error(w, "Error iterating over rows: : "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error iterating over rows: "+err.Error(), http.StatusInternalServerError) return } @@ -31,7 +37,7 @@ func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) err = templates.ExecuteTemplate(w, "index", params) if err != nil { - http.Error(w, "Error rendering template: : "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) return } } |