Migration This is my new public git source viewer. Source coming soon. Please contact with concerns/bugs. Contact me

internal/site/routes.go

d658fcc4ea9f3bb562fd00dce8f863934560c56c · 3.1 KB · 85 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 PageSize: core.LogPageSize},
42
43 {Name: "blob",
44 Pattern: "GET /{repo}/blob/{rest...}",
45 Render: core.View{Template: "blob.html"}},
46
47 // Actual file bytes. See core.Raw for why this is not text/html.
48 {Name: "raw",
49 Pattern: "GET /{repo}/raw/{rest...}",
50 Render: core.Raw{Module: "blobraw"}},
51
52 // The DAG across every ref. {rest...} carries only a ref (never a
53 // path, there's nothing to browse into) -- it exists purely so the
54 // selected branch survives navigating here and back out again.
55 {Name: "graph", NavLabel: "graph", CacheableAnone: true,
56 Pattern: "GET /{repo}/graph/{rest...}",
57 Render: core.View{Template: "graph.html"},
58 PageSize: core.GraphPageSize},
59
60 {Name: "refs", NavLabel: "refs", CacheableAnon: true,
61 Pattern: "GET /{repo}/refs/{rest...}",
62 Render: core.View{Template: "refs.html"}},
63
64 // Arbitrary two-commit diff: /demo/compare/main...feature. Not
65 // CacheableAnon: a diff body is bounded only by MaxGit (16 MiB,
66 // larger than a blob preview), and every valid ref pair is a
67 // distinct key -- a repo with N refs has ~N^2 reachable ones. The
68 // response cache has no size-aware eviction, so this route would
69 // risk filling it with a few huge entries for no real hit-rate
70 // benefit (see internal/core/route.go's CacheableAnon doc).
71 {Name: "compare",
72 Pattern: "GET /{repo}/compare/{range}",
73 Render: core.View{Template: "compare.html"},
74 Request: CompareRequest},
75
76 // SHA-addressed: content can never change, so cache forever.
77 {Name: "commit", Immutable: true,
78 Pattern: "GET /{repo}/commit/{rev}",
79 Render: core.View{Template: "commit.html"}},
80
81 {Name: "api-commit", Immutable: true,
82 Pattern: "GET /{repo}/api/commit/{rev}",
83 Render: core.JSON{Build: api.CommitEndpoint}},
84 }
85 }