DEVELOPMENT ENVIRONMENT

~liljamo/tixe

9e1c26e603bf15bf550dbc041c7f23159ab4bccd — Jonni Liljamo 1 year, 1 month ago 2e864c4
feat: show version number in settings
5 files changed, 37 insertions(+), 12 deletions(-)

M Dockerfile
M handlers/settings.go
M static/styles.css
M template/templates/settings.tmpl
M tixe.go
M Dockerfile => Dockerfile +3 -1
@@ 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

M handlers/settings.go => handlers/settings.go +14 -10
@@ 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)
}

M static/styles.css => static/styles.css +9 -0
@@ 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;
}

M template/templates/settings.tmpl => template/templates/settings.tmpl +8 -0
@@ 6,6 6,7 @@
>
	Settings
</p>

<form class="flex flex-col" action="/api/settings/user/display_name" method="POST">
	<p class="text-sm" for="display_name">Display Name</p>
	<div class="flex gap-2">


@@ 15,4 16,11 @@
		</button>
	</div>
</form>

<div class="p-8">
	<div class="flex gap-1">
		<p class="text-xs">tixë version:</p>
		<p class="text-xs font-bold text-amber-500">{{ .version }}</p>
	</div>
</div>
{{ end }}

M tixe.go => tixe.go +3 -1
@@ 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)