From 9e1c26e603bf15bf550dbc041c7f23159ab4bccd Mon Sep 17 00:00:00 2001
From: Jonni Liljamo
Date: Thu, 5 Oct 2023 19:06:48 +0300
Subject: [PATCH] feat: show version number in settings
---
Dockerfile | 4 +++-
handlers/settings.go | 24 ++++++++++++++----------
static/styles.css | 9 +++++++++
template/templates/settings.tmpl | 8 ++++++++
tixe.go | 4 +++-
5 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index 8b980ad..edcdcb8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,8 @@
# builder
FROM golang:1.21.0-alpine AS builder
+ARG VERSION=notset-dockerfile
+
WORKDIR /usr/src/app
COPY go.mod go.sum ./
@@ -9,7 +11,7 @@ RUN go mod download && go mod verify
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
-CGO_ENABLED=0 GOOS=linux go build -v -o /tixe ./tixe.go
+CGO_ENABLED=0 GOOS=linux go build -ldflags=-X=main.version=${VERSION} -v -o /tixe ./tixe.go
# tester
FROM builder AS tester
diff --git a/handlers/settings.go b/handlers/settings.go
index 287e96a..c3edac6 100644
--- a/handlers/settings.go
+++ b/handlers/settings.go
@@ -18,18 +18,22 @@ import (
type SettingsData struct {
}
-func Settings(c *gin.Context) {
- session := sessions.Default(c)
- user := session.Get("user").(types.User)
+func Settings(version string) gin.HandlerFunc {
+ fn := func(c* gin.Context) {
+ session := sessions.Default(c)
+ user := session.Get("user").(types.User)
- // This now comes from the session data, but kept as reference for other things
- //var displayName string
- //_ = db.PgPool.QueryRow(context.Background(),
- // "SELECT display_name FROM users WHERE id = $1", user.Id).Scan(&displayName)
+ // This now comes from the session data, but kept as reference for other things
+ //var displayName string
+ //_ = db.PgPool.QueryRow(context.Background(),
+ // "SELECT display_name FROM users WHERE id = $1", user.Id).Scan(&displayName)
- settingsData := SettingsData {
+ settingsData := SettingsData {
+ }
+
+ html := template.TmplEngine.Render("settings.tmpl", map[string]interface{}{"title": "settings", "user": user, "data": settingsData, "version": version})
+ c.Data(http.StatusOK, "text/html", html)
}
- html := template.TmplEngine.Render("settings.tmpl", map[string]interface{}{"title": "settings", "user": user, "data": settingsData})
- c.Data(http.StatusOK, "text/html", html)
+ return gin.HandlerFunc(fn)
}
diff --git a/static/styles.css b/static/styles.css
index 17c303c..5f331cd 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -855,6 +855,10 @@ video {
padding: 1rem;
}
+.p-8 {
+ padding: 2rem;
+}
+
.px-2 {
padding-left: 0.5rem;
padding-right: 0.5rem;
@@ -901,6 +905,11 @@ video {
color: transparent;
}
+.text-amber-500 {
+ --tw-text-opacity: 1;
+ color: rgb(245 158 11 / var(--tw-text-opacity));
+}
+
.opacity-0 {
opacity: 0;
}
diff --git a/template/templates/settings.tmpl b/template/templates/settings.tmpl
index 884e0b4..985b197 100644
--- a/template/templates/settings.tmpl
+++ b/template/templates/settings.tmpl
@@ -6,6 +6,7 @@
>
Settings
+
+
+
+
+
tixë version:
+
{{ .version }}
+
+
{{ end }}
diff --git a/tixe.go b/tixe.go
index b79f214..fd50b6c 100644
--- a/tixe.go
+++ b/tixe.go
@@ -24,6 +24,8 @@ import (
"github.com/gin-gonic/gin"
)
+var version = "notset-builtin";
+
func ping(c *gin.Context) {
c.String(http.StatusOK, "pong")
}
@@ -63,7 +65,7 @@ func setupRouter(auth *auth.Auth) *gin.Engine {
reqAuth.GET("/", handlers.Index)
reqAuth.GET("/tags", handlers.Tags)
- reqAuth.GET("/settings", handlers.Settings)
+ reqAuth.GET("/settings", handlers.Settings(version))
reqAuth.GET("/link/:id", handlers.LinkEdit)
--
2.44.1