Extract clientip middleware and add jsonutil helpers

Move clientIP extraction into a reusable pkg/server/api/clientip
package with RFC 7239 Forwarded header support. Add
pkg/server/jsonutil with helpers for common HTTP error responses
(RenderForbidden, RenderInternalServerError, RenderNotFound,
RenderBadRequest) and use them in the cookie banner handlers.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-14 17:02:08 +04:00
parent abd565c96a
commit 7a50537bf4
6 changed files with 205 additions and 62 deletions

View File

@@ -140,11 +140,14 @@ FROM
cookie_banners
WHERE
id = @banner_id
AND state = 'ACTIVE'
AND state = @state
LIMIT 1;
`
args := pgx.StrictNamedArgs{"banner_id": bannerID}
args := pgx.StrictNamedArgs{
"banner_id": bannerID,
"state": CookieBannerStateActive,
}
rows, err := conn.Query(ctx, q, args)
if err != nil {
@@ -188,13 +191,16 @@ FROM
WHERE
%s
AND origin = @origin
AND state = 'ACTIVE'
AND state = @state
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"origin": origin}
args := pgx.StrictNamedArgs{
"origin": origin,
"state": CookieBannerStateActive,
}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)

View File

@@ -450,14 +450,17 @@ FROM
WHERE
%s
AND cookie_banner_id = @cookie_banner_id
AND state = 'PUBLISHED'
AND state = @state
ORDER BY version DESC
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"cookie_banner_id": cookieBannerID}
args := pgx.StrictNamedArgs{
"cookie_banner_id": cookieBannerID,
"state": CookieBannerVersionStatePublished,
}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)