From 134b84f2672a9fe3e2e8a92b712261b47c4bd022 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Wed, 5 Mar 2025 09:32:40 +0800 Subject: repo/*: Use var instead of := --- http_handle_repo_contrib_index.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'http_handle_repo_contrib_index.go') diff --git a/http_handle_repo_contrib_index.go b/http_handle_repo_contrib_index.go index 2e0dc1d..f352a3f 100644 --- a/http_handle_repo_contrib_index.go +++ b/http_handle_repo_contrib_index.go @@ -5,6 +5,8 @@ package main import ( "net/http" + + "github.com/jackc/pgx/v5" ) type id_title_status_t struct { @@ -14,24 +16,29 @@ type id_title_status_t struct { } func handle_repo_contrib_index(w http.ResponseWriter, r *http.Request, params map[string]any) { - rows, err := database.Query(r.Context(), "SELECT id, COALESCE(title, 'Untitled'), status FROM merge_requests WHERE repo_id = $1", params["repo_id"]) - if err != nil { + var rows pgx.Rows + var result []id_title_status_t + var err error + + if rows, err = database.Query(r.Context(), + "SELECT id, COALESCE(title, 'Untitled'), status FROM merge_requests WHERE repo_id = $1", + params["repo_id"], + ); err != nil { http.Error(w, "Error querying merge requests: "+err.Error(), http.StatusInternalServerError) return } defer rows.Close() - result := []id_title_status_t{} for rows.Next() { var id int var title, status string - if err := rows.Scan(&id, &title, &status); err != nil { + if err = rows.Scan(&id, &title, &status); err != nil { http.Error(w, "Error scanning merge request: "+err.Error(), http.StatusInternalServerError) return } result = append(result, id_title_status_t{id, title, status}) } - if err := rows.Err(); err != nil { + if err = rows.Err(); err != nil { http.Error(w, "Error ranging over merge requests: "+err.Error(), http.StatusInternalServerError) return } -- cgit v1.2.3