| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | package web |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "fmt" |
| 8 | "log/slog" |
| 9 | "path/filepath" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgxpool" |
| 12 | |
| 13 | "github.com/tenseleyFlow/shithub/internal/infra/config" |
| 14 | "github.com/tenseleyFlow/shithub/internal/infra/storage" |
| 15 | githttph "github.com/tenseleyFlow/shithub/internal/web/handlers/githttp" |
| 16 | ) |
| 17 | |
| 18 | // buildGitHTTPHandlers wires the smart-HTTP route handlers. The bare |
| 19 | // repos live at cfg.Storage.ReposRoot; we refuse to boot the git-HTTP |
| 20 | // surface without it. |
| 21 | func buildGitHTTPHandlers( |
| 22 | cfg config.Config, |
| 23 | pool *pgxpool.Pool, |
| 24 | logger *slog.Logger, |
| 25 | ) (*githttph.Handlers, error) { |
| 26 | if cfg.Storage.ReposRoot == "" { |
| 27 | return nil, errors.New("git-http: cfg.Storage.ReposRoot is empty") |
| 28 | } |
| 29 | root, err := filepath.Abs(cfg.Storage.ReposRoot) |
| 30 | if err != nil { |
| 31 | return nil, fmt.Errorf("git-http: resolve repos_root: %w", err) |
| 32 | } |
| 33 | rfs, err := storage.NewRepoFS(root) |
| 34 | if err != nil { |
| 35 | return nil, fmt.Errorf("git-http: NewRepoFS: %w", err) |
| 36 | } |
| 37 | return githttph.New(githttph.Deps{ |
| 38 | Logger: logger, |
| 39 | Pool: pool, |
| 40 | RepoFS: rfs, |
| 41 | }) |
| 42 | } |
| 43 |