From 43ce34219c32f44a9bccb94bbe3f66ede5796550 Mon Sep 17 00:00:00 2001 From: igor Date: Thu, 22 Jan 2026 13:09:22 +0100 Subject: [PATCH] formatovany kod pomocou `gofmt` --- dbPrompt.go | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/dbPrompt.go b/dbPrompt.go index 4560d2d..ffd74be 100644 --- a/dbPrompt.go +++ b/dbPrompt.go @@ -34,13 +34,13 @@ type QueryRequest struct { // QueryResult represents a single historical query execution type QueryResult struct { - ID string `json:"id"` - Query string `json:"query"` - Timestamp int64 `json:"timestamp"` - Error string `json:"error,omitempty"` - Columns []string `json:"columns,omitempty"` - Rows [][]interface{} `json:"rows,omitempty"` - RowsAffected int64 `json:"rowsAffected,omitempty"` + ID string `json:"id"` + Query string `json:"query"` + Timestamp int64 `json:"timestamp"` + Error string `json:"error,omitempty"` + Columns []string `json:"columns,omitempty"` + Rows [][]interface{} `json:"rows,omitempty"` + RowsAffected int64 `json:"rowsAffected,omitempty"` } var db *sql.DB @@ -141,10 +141,10 @@ func handleQuery(w http.ResponseWriter, r *http.Request) { Timestamp: time.Now().UnixNano(), } - // Generate new ID if it's a new query - if result.ID == "" { - result.ID = strconv.FormatInt(result.Timestamp, 10) - } + // Generate new ID if it's a new query + if result.ID == "" { + result.ID = strconv.FormatInt(result.Timestamp, 10) + } if isSelect { // It's a query that returns rows @@ -155,21 +155,21 @@ func handleQuery(w http.ResponseWriter, r *http.Request) { defer rows.Close() cols, _ := rows.Columns() result.Columns = cols - - for rows.Next() { - // Create a slice of interface{}'s to represent a row - columns := make([]interface{}, len(cols)) - columnPointers := make([]interface{}, len(cols)) - for i := range columns { - columnPointers[i] = &columns[i] - } - // Scan the result into the column pointers... - if err := rows.Scan(columnPointers...); err != nil { - result.Error = err.Error() - break - } - + for rows.Next() { + // Create a slice of interface{}'s to represent a row + columns := make([]interface{}, len(cols)) + columnPointers := make([]interface{}, len(cols)) + for i := range columns { + columnPointers[i] = &columns[i] + } + + // Scan the result into the column pointers... + if err := rows.Scan(columnPointers...); err != nil { + result.Error = err.Error() + break + } + // Convert byte slices to strings for better JSON representation for i, col := range columns { if b, ok := col.([]byte); ok { @@ -177,7 +177,7 @@ func handleQuery(w http.ResponseWriter, r *http.Request) { } } - result.Rows = append(result.Rows, columns) + result.Rows = append(result.Rows, columns) } if err := rows.Err(); err != nil { result.Error = err.Error() @@ -208,4 +208,4 @@ func handleQuery(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(result) -} \ No newline at end of file +}