diff --git a/src/db/dblist.go b/src/db/dblist.go index 6788c9f..7f9ff28 100644 --- a/src/db/dblist.go +++ b/src/db/dblist.go @@ -9,6 +9,8 @@ import ( "time" + "slices" + "github.com/google/uuid" "github.com/sirupsen/logrus" ) @@ -42,7 +44,7 @@ func (o *DbList) GetByParams(connInfo *DbConnInfo) (string, bool) { // Step 1. Search existing connection by hash to reuse guid := "" o.items.Range( - func(key, value interface{}) bool { + func(key, value any) bool { if bytes.Equal(value.(*DbConn).Hash[:], hash[:]) { guid = key.(string) app.Log.Debugf("DB connection with id %s found in the pool", guid) @@ -191,10 +193,10 @@ func (o *DbList) ClosePreparedStatement(conn_id, stmt_id string) bool { return false } res := val.(*DbConn) - for i := 0; i < len(res.Stmt); i++ { + for i := range res.Stmt { if res.Stmt[i].Id == stmt_id { res.Stmt[i].Stmt.Close() - res.Stmt = append(res.Stmt[:i], res.Stmt[i+1:]...) + res.Stmt = slices.Delete(res.Stmt, i, i+1) break } } @@ -216,7 +218,7 @@ func (o *DbList) RunMaintenance() { var countConn, countDeadConn, countStmt int o.items.Range( - func(key, value interface{}) bool { + func(key, value any) bool { var lostStmts []string countConn++ dbConn := value.(*DbConn) @@ -245,7 +247,7 @@ func (o *DbList) RunMaintenance() { for i := 0; i < len(dbConn.Stmt); i++ { if dbConn.Stmt[i].Id == lost { dbConn.Stmt[i].Stmt.Close() - dbConn.Stmt = append(dbConn.Stmt[:i], dbConn.Stmt[i+1:]...) + dbConn.Stmt = slices.Delete(dbConn.Stmt, i, i+1) break } } diff --git a/src/handlers/convert.go b/src/handlers/convert.go index 110fd59..082986b 100644 --- a/src/handlers/convert.go +++ b/src/handlers/convert.go @@ -6,12 +6,12 @@ import ( ) // Converts SQL query result to json -func convertRows(rows *sql.Rows, columns *[]string) (*[]map[string]interface{}, uint32, bool) { +func convertRows(rows *sql.Rows, columns *[]string) (*[]map[string]any, uint32, bool) { var rowsCount uint32 = 0 colsCount := len(*columns) - tableData := make([]map[string]interface{}, 0) - values := make([]interface{}, colsCount) - valuePtrs := make([]interface{}, colsCount) + tableData := make([]map[string]any, 0) + values := make([]any, colsCount) + valuePtrs := make([]any, colsCount) exceedsMaxRows := false for rows.Next() { @@ -19,9 +19,9 @@ func convertRows(rows *sql.Rows, columns *[]string) (*[]map[string]interface{}, valuePtrs[i] = &values[i] } rows.Scan(valuePtrs...) - entry := make(map[string]interface{}) + entry := make(map[string]any) for i, col := range *columns { - var v interface{} + var v any val := values[i] b, ok := val.([]byte) if ok { diff --git a/src/handlers/envelope.go b/src/handlers/envelope.go index ac975d6..530d465 100644 --- a/src/handlers/envelope.go +++ b/src/handlers/envelope.go @@ -1,10 +1,10 @@ package handlers type ResponseEnvelope struct { - ApiVersion uint8 `json:"api_version"` - ConnectionId string `json:"connection_id"` - Info string `json:"info"` - RowsCount uint32 `json:"rows_count"` - ExceedsMaxRows bool `json:"exceeds_max_rows"` - Rows []map[string]interface{} `json:"rows"` + ApiVersion uint8 `json:"api_version"` + ConnectionId string `json:"connection_id"` + Info string `json:"info"` + RowsCount uint32 `json:"rows_count"` + ExceedsMaxRows bool `json:"exceeds_max_rows"` + Rows []map[string]any `json:"rows"` } diff --git a/src/handlers/prepared.go b/src/handlers/prepared.go index d73c89f..ef37c8a 100644 --- a/src/handlers/prepared.go +++ b/src/handlers/prepared.go @@ -7,7 +7,7 @@ import ( ) func PrepareStatement(w http.ResponseWriter, r *http.Request) { - var requestBody map[string]interface{} + var requestBody map[string]any err := json.NewDecoder(r.Body).Decode(&requestBody) if err != nil { http.Error(w, "Error decoding JSON", http.StatusBadRequest) @@ -38,7 +38,7 @@ func PrepareStatement(w http.ResponseWriter, r *http.Request) { } func PreparedSelect(w http.ResponseWriter, r *http.Request) { - var requestBody map[string]interface{} + var requestBody map[string]any err := json.NewDecoder(r.Body).Decode(&requestBody) if err != nil { http.Error(w, "Error decoding JSON", http.StatusBadRequest)