Migration
This is my new public git source viewer. Source coming soon. Please contact with concerns/bugs.
Contact me
internal/site/routes.go
caching_trials
· 3.1 KB · 82 lines
raw
| 1 | // Package site is the route table: the one file you edit when adding a |
| 2 | // page or an endpoint. Modules are the "what", routes are the "where". |
| 3 | package site |
| 4 | |
| 5 | import ( |
| 6 | "gsg/internal/api" |
| 7 | "gsg/internal/core" |
| 8 | ) |
| 9 | |
| 10 | func Routes() []core.Route { |
| 11 | return []core.Route{ |
| 12 | // ---- site-scoped ------------------------------------------------- |
| 13 | {Name: "index", Scope: core.ScopeSite, CacheableAnon: true, |
| 14 | Pattern: "GET /{$}", |
| 15 | Render: core.View{Template: "index.html"}}, |
| 16 | |
| 17 | {Name: "api-index", Scope: core.ScopeSite, |
| 18 | Pattern: "GET /api/repos.json", |
| 19 | Render: core.JSON{Build: api.IndexEndpoint}}, |
| 20 | |
| 21 | // ---- per repository ---------------------------------------------- |
| 22 | // NavLabel order below is the order tabs appear in the repo-scoped |
| 23 | // nav (top bar and page-nav chips) -- see core.BuildNav. |
| 24 | {Name: "repo", CacheableAnon: true, |
| 25 | Pattern: "GET /{repo}/{$}", |
| 26 | Render: core.View{Template: "tree.html"}}, |
| 27 | |
| 28 | {Name: "api-repo", |
| 29 | Pattern: "GET /{repo}/api/repo.json", |
| 30 | Render: core.JSON{Build: api.RepoEndpoint}}, |
| 31 | |
| 32 | // {rest...} fuses ref and path; SplitRefPath separates them by |
| 33 | // longest-matching ref, so feature/x/src/main.go works. |
| 34 | {Name: "tree", NavLabel: "files", CacheableAnon: true, |
| 35 | Pattern: "GET /{repo}/tree/{rest...}", |
| 36 | Render: core.View{Template: "tree.html"}}, |
| 37 | |
| 38 | {Name: "log", NavLabel: "log", CacheableAnon: true, |
| 39 | Pattern: "GET /{repo}/log/{rest...}", |
| 40 | Render: core.View{Template: "log.html"}}, |
| 41 | |
| 42 | {Name: "blob", |
| 43 | Pattern: "GET /{repo}/blob/{rest...}", |
| 44 | Render: core.View{Template: "blob.html"}}, |
| 45 | |
| 46 | // Actual file bytes. See core.Raw for why this is not text/html. |
| 47 | {Name: "raw", |
| 48 | Pattern: "GET /{repo}/raw/{rest...}", |
| 49 | Render: core.Raw{Module: "blobraw"}}, |
| 50 | |
| 51 | // The DAG across every ref. {rest...} carries only a ref (never a |
| 52 | // path, there's nothing to browse into) -- it exists purely so the |
| 53 | // selected branch survives navigating here and back out again. |
| 54 | {Name: "graph", NavLabel: "graph", CacheableAnon: true, |
| 55 | Pattern: "GET /{repo}/graph/{rest...}", |
| 56 | Render: core.View{Template: "graph.html"}}, |
| 57 | |
| 58 | {Name: "refs", NavLabel: "refs", CacheableAnon: true, |
| 59 | Pattern: "GET /{repo}/refs/{rest...}", |
| 60 | Render: core.View{Template: "refs.html"}}, |
| 61 | |
| 62 | // Arbitrary two-commit diff: /demo/compare/main...feature. Not |
| 63 | // CacheableAnon: a diff body is bounded only by MaxGit (16 MiB, |
| 64 | // larger than a blob preview), and every valid ref pair is a |
| 65 | // distinct key -- a repo with N refs has ~N^2 reachable ones. The |
| 66 | // response cache has no size-aware eviction, so this route would |
| 67 | // risk filling it with a few huge entries for no real hit-rate |
| 68 | // benefit (see internal/core/route.go's CacheableAnon doc). |
| 69 | {Name: "compare", |
| 70 | Pattern: "GET /{repo}/compare/{range}", |
| 71 | Render: core.View{Template: "compare.html"}}, |
| 72 | |
| 73 | // SHA-addressed: content can never change, so cache forever. |
| 74 | {Name: "commit", Immutable: true, |
| 75 | Pattern: "GET /{repo}/commit/{rev}", |
| 76 | Render: core.View{Template: "commit.html"}}, |
| 77 | |
| 78 | {Name: "api-commit", Immutable: true, |
| 79 | Pattern: "GET /{repo}/api/commit/{rev}", |
| 80 | Render: core.JSON{Build: api.CommitEndpoint}}, |
| 81 | } |
| 82 | } |