From 1660282ccc8c2ef8949c0416e206dc175a977722 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 14 Feb 2025 08:56:07 +0800 Subject: {database,http_handle_*index}.go: Reduce query_name_desc_list duplication --- http_handle_index.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'http_handle_index.go') diff --git a/http_handle_index.go b/http_handle_index.go index 41a55e8..ee92c49 100644 --- a/http_handle_index.go +++ b/http_handle_index.go @@ -5,30 +5,12 @@ import ( ) func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) { - rows, err := database.Query(r.Context(), "SELECT name, COALESCE(description, '') FROM groups") + groups, err := query_name_desc_list(r.Context(), "SELECT name, COALESCE(description, '') FROM groups") if err != nil { http.Error(w, "Error querying groups: "+err.Error(), http.StatusInternalServerError) return } - defer rows.Close() - - groups := []name_desc_t{} - for rows.Next() { - 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, name_desc_t{groupName, groupDescription}) - } - - if err := rows.Err(); err != nil { - http.Error(w, "Error iterating over rows: "+err.Error(), http.StatusInternalServerError) - return - } - params["groups"] = groups - err = templates.ExecuteTemplate(w, "index", params) if err != nil { http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) -- cgit v1.2.3