Skip to content

Commit ff2994c

Browse files
committed
web: show version and API docs link in footer
Display the build version and a link to the API documentation in the web interface footer. Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent 278f527 commit ff2994c

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

cmd/pw/http/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (c *CLI) Run(ctx *pw.Context) error {
3737
bus := events.Start(ctx, ctx.DB)
3838
defer bus.Shutdown()
3939

40-
router := web.NewRouter(ctx.Config, ctx.DB, bus)
40+
router := web.NewRouter(ctx.Config, ctx.DB, bus, ctx.Version)
4141
router.Mount("/", api.NewRouter(ctx.Config, ctx.DB, ctx.Config.Http.BaseURL, bus))
4242

4343
srv := &http.Server{

pkg/web/layout.templ

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type breadcrumb struct {
1515
type pageContext struct {
1616
User *db.User
1717
CSRFToken string
18+
Version string
1819
}
1920

2021
templ layout(title string, crumbs []breadcrumb, pc pageContext) {
@@ -60,7 +61,7 @@ templ layout(title string, crumbs []breadcrumb, pc pageContext) {
6061
{ children... }
6162
</main>
6263
<footer>
63-
Patchwork
64+
Patchwork { pc.Version } | <a href="/api/docs">API</a>
6465
</footer>
6566
</body>
6667
</html>

pkg/web/web.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
//go:embed static/*
3131
var staticFS embed.FS
3232

33-
func NewRouter(cfg *config.Config, database *bun.DB, bus db.EventBus) chi.Router {
33+
func NewRouter(cfg *config.Config, database *bun.DB, bus db.EventBus, version string) chi.Router {
3434
r := chi.NewRouter()
3535
r.Use(middleware.Recoverer)
3636
r.Use(middleware.StripSlashes)
@@ -40,7 +40,7 @@ func NewRouter(cfg *config.Config, database *bun.DB, bus db.EventBus) chi.Router
4040
if _, err := rand.Read(csrfKey); err != nil {
4141
panic("generate CSRF key: " + err.Error())
4242
}
43-
h := &webHandler{cfg: cfg, db: database, csrfKey: csrfKey}
43+
h := &webHandler{cfg: cfg, db: database, csrfKey: csrfKey, version: version}
4444
r.Use(h.sessionMiddleware)
4545

4646
sub, _ := fs.Sub(staticFS, "static")
@@ -108,6 +108,7 @@ type webHandler struct {
108108
cfg *config.Config
109109
db *bun.DB
110110
csrfKey []byte
111+
version string
111112
}
112113

113114
func intStr(n int) string {
@@ -261,6 +262,7 @@ func (h *webHandler) pageCtx(r *http.Request) pageContext {
261262
return pageContext{
262263
User: getWebUser(r),
263264
CSRFToken: h.csrfToken(r),
265+
Version: h.version,
264266
}
265267
}
266268

0 commit comments

Comments
 (0)