| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | package web |
| 4 | |
| 5 | import ( |
| 6 | "io/fs" |
| 7 | "log/slog" |
| 8 | |
| 9 | "github.com/jackc/pgx/v5/pgxpool" |
| 10 | |
| 11 | "github.com/tenseleyFlow/shithub/internal/ratelimit" |
| 12 | searchhandlers "github.com/tenseleyFlow/shithub/internal/web/handlers/search" |
| 13 | "github.com/tenseleyFlow/shithub/internal/web/render" |
| 14 | ) |
| 15 | |
| 16 | // buildSearchHandlers wires the S28 search handler set. Owns its own |
| 17 | // renderer (same pattern as the other handler builders). |
| 18 | // |
| 19 | // Limiter is the per-request rate-limit entrypoint applied to /search |
| 20 | // (audit 2026-05-10 H4). Pass nil from tests when you don't care |
| 21 | // about throttling; production wiring constructs one shared limiter |
| 22 | // per shithubd-web process and threads it everywhere. |
| 23 | func buildSearchHandlers( |
| 24 | pool *pgxpool.Pool, |
| 25 | tmplFS fs.FS, |
| 26 | logger *slog.Logger, |
| 27 | limiter *ratelimit.Limiter, |
| 28 | ) (*searchhandlers.Handlers, error) { |
| 29 | rr, err := render.New(tmplFS, render.Options{Octicons: render.BuiltinOcticons()}) |
| 30 | if err != nil { |
| 31 | return nil, err |
| 32 | } |
| 33 | return searchhandlers.New(searchhandlers.Deps{ |
| 34 | Logger: logger, Render: rr, Pool: pool, Limiter: limiter, |
| 35 | }) |
| 36 | } |
| 37 |