mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-17 02:50:00 +00:00
* feat(logging): configure levels and structured runtime output * fix(logging): bound request-derived log fields * fix(logging): retain malformed IATA source attributes safely * test(logging): capture structured REST rate-limit records
34 lines
820 B
Go
34 lines
820 B
Go
// Copyright 2026 Beacon Contributors
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package handlers
|
|
|
|
import (
|
|
"errors"
|
|
"log/slog"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
const maxListLimit int32 = 200
|
|
|
|
// parseLimit caps the requested result size while retaining each endpoint's default.
|
|
func parseLimit(r *http.Request, defaultLimit int32) (int32, error) {
|
|
value := r.URL.Query().Get("limit")
|
|
if value == "" {
|
|
return defaultLimit, nil
|
|
}
|
|
limit, err := strconv.ParseInt(value, 10, 32)
|
|
if err != nil {
|
|
return 0, errors.New("limit must be an integer")
|
|
}
|
|
if limit <= 0 {
|
|
return 0, errors.New("limit must be positive")
|
|
}
|
|
if limit > int64(maxListLimit) {
|
|
slog.Info("api: clamped list limit", "component", "api", "requested_limit", limit, "limit", maxListLimit)
|
|
return maxListLimit, nil
|
|
}
|
|
return int32(limit), nil
|
|
}
|