fix(api-key): check usage log rows close

This commit is contained in:
wucm667
2026-07-08 15:36:12 +08:00
parent e0d149d511
commit 7a11b39d6d
+6 -2
View File
@@ -462,7 +462,7 @@ func (r *apiKeyRepository) attachLastUsedIPs(ctx context.Context, keys []service
return nil
}
func (r *apiKeyRepository) latestUsageLogIPs(ctx context.Context, apiKeyIDs []int64) (map[int64]string, error) {
func (r *apiKeyRepository) latestUsageLogIPs(ctx context.Context, apiKeyIDs []int64) (result map[int64]string, err error) {
if len(apiKeyIDs) == 0 || r.sql == nil {
return map[int64]string{}, nil
}
@@ -472,7 +472,11 @@ func (r *apiKeyRepository) latestUsageLogIPs(ctx context.Context, apiKeyIDs []in
if err != nil {
return nil, err
}
defer rows.Close()
defer func() {
if closeErr := rows.Close(); closeErr != nil && err == nil {
err = closeErr
}
}()
out := make(map[int64]string, len(apiKeyIDs))
for rows.Next() {