formatovany kod pomocou gofmt

This commit is contained in:
2026-01-22 13:09:22 +01:00
parent 6df8e53b53
commit 43ce34219c

View File

@ -34,13 +34,13 @@ type QueryRequest struct {
// QueryResult represents a single historical query execution // QueryResult represents a single historical query execution
type QueryResult struct { type QueryResult struct {
ID string `json:"id"` ID string `json:"id"`
Query string `json:"query"` Query string `json:"query"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
Error string `json:"error,omitempty"` Error string `json:"error,omitempty"`
Columns []string `json:"columns,omitempty"` Columns []string `json:"columns,omitempty"`
Rows [][]interface{} `json:"rows,omitempty"` Rows [][]interface{} `json:"rows,omitempty"`
RowsAffected int64 `json:"rowsAffected,omitempty"` RowsAffected int64 `json:"rowsAffected,omitempty"`
} }
var db *sql.DB var db *sql.DB
@ -141,10 +141,10 @@ func handleQuery(w http.ResponseWriter, r *http.Request) {
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
} }
// Generate new ID if it's a new query // Generate new ID if it's a new query
if result.ID == "" { if result.ID == "" {
result.ID = strconv.FormatInt(result.Timestamp, 10) result.ID = strconv.FormatInt(result.Timestamp, 10)
} }
if isSelect { if isSelect {
// It's a query that returns rows // It's a query that returns rows
@ -155,21 +155,21 @@ func handleQuery(w http.ResponseWriter, r *http.Request) {
defer rows.Close() defer rows.Close()
cols, _ := rows.Columns() cols, _ := rows.Columns()
result.Columns = cols 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... for rows.Next() {
if err := rows.Scan(columnPointers...); err != nil { // Create a slice of interface{}'s to represent a row
result.Error = err.Error() columns := make([]interface{}, len(cols))
break 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 // Convert byte slices to strings for better JSON representation
for i, col := range columns { for i, col := range columns {
if b, ok := col.([]byte); ok { 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 { if err := rows.Err(); err != nil {
result.Error = err.Error() result.Error = err.Error()
@ -208,4 +208,4 @@ func handleQuery(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(result) json.NewEncoder(w).Encode(result)
} }