From 32cd1ff49569870a2dcd6a3143df16f16e6ee318 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 31 Aug 2025 10:41:16 -0400 Subject: [PATCH] Latest changes from my twitter for coders project brought back. --- data/models.go | 23 ++++++++- go.mod | 1 + go.sum | 2 + migrations/20250802154952_init.sql | 6 --- pages/index.md | 2 + pages/layouts/main.html | 55 ++++++++++++++------ static/icons/arrow-big-up.svg | 1 + static/icons/bookmark.svg | 1 + static/icons/heart.svg | 1 + static/icons/log-in.svg | 1 + static/icons/log-out.svg | 1 + static/icons/message-square.svg | 1 + static/icons/refresh-cw.svg | 1 + static/icons/reply.svg | 1 + static/icons/rss.svg | 1 + static/icons/settings.svg | 1 + static/icons/user-plus.svg | 1 + static/input_style.css | 21 +++++--- static/js/alpine-intersect.js | 1 + static/js/code.js | 49 +++++++++++++++--- static/style.css | 54 ++++++++++---------- tools/pragmas.sql | 6 +++ views/admin/table/new.html | 16 +++--- views/admin/table/view.html | 8 ++- views/layouts/main.html | 80 +++++++++++++++++++----------- 25 files changed, 230 insertions(+), 105 deletions(-) create mode 100644 static/js/alpine-intersect.js create mode 100644 tools/pragmas.sql diff --git a/data/models.go b/data/models.go index 4d9754d..6fe4e13 100644 --- a/data/models.go +++ b/data/models.go @@ -1,6 +1,9 @@ package data -import "reflect" +import ( + "reflect" + "github.com/guregu/null/v6" +) type Login struct { Username string `db:"username" validate:"required,max=30"` @@ -14,8 +17,26 @@ type User struct { Password string `db:"password" validate:"required,min=8,max=64"` } +type Message struct { + Id int `db:"id" json:"id" validate:"numeric"` + Text string `db:"text" json:"text" validate:"required,max=512"` + UserId int `db:"user_id" json:"user_id" validate:"numeric"` + CreatedAt string `db:"created_at" json:"created_at"` + Likes int `db:"likes" json:"likes" validate:"numeric"` + Bookmarks int `db:"bookmarks" json:"bookmarks" validate:"numeric"` + ReplyingTo null.Int `db:"replying_to" json:"replying_to" validate:"omitempty,numeric"` +} + + +type Bookmark struct { + MessageId int `db:"message_id" json:"message_id" validate:"required,numeric"` + UserId int `db:"user_id" json:"user_id" validate:"required,numeric"` +} + func Models() map[string]reflect.Type { return map[string]reflect.Type{ "user": reflect.TypeFor[User](), + "message": reflect.TypeFor[Message](), + "bookmark": reflect.TypeFor[Bookmark](), } } diff --git a/go.mod b/go.mod index 6be0c03..37610ba 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/go-playground/validator/v10 v10.26.0 github.com/gofiber/fiber/v2 v2.52.8 github.com/gofiber/template/html/v2 v2.1.3 + github.com/guregu/null/v6 v6.0.0 github.com/jmoiron/sqlx v1.4.0 github.com/mattn/go-sqlite3 v1.14.28 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index 3e62bca..b293dde 100644 --- a/go.sum +++ b/go.sum @@ -231,6 +231,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/guregu/null/v6 v6.0.0 h1:N14VRS+4di81i1PXRiprbQJ9EM9gqBa0+KVMeS/QSjQ= +github.com/guregu/null/v6 v6.0.0/go.mod h1:hrMIhIfrOZeLPZhROSn149tpw2gHkidAqxoXNyeX3iQ= github.com/hairyhenderson/go-codeowners v0.7.0 h1:s0W4wF8bdsBEjTWzwzSlsatSthWtTAF2xLgo4a4RwAo= github.com/hairyhenderson/go-codeowners v0.7.0/go.mod h1:wUlNgQ3QjqC4z8DnM5nnCYVq/icpqXJyJOukKx5U8/Q= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= diff --git a/migrations/20250802154952_init.sql b/migrations/20250802154952_init.sql index 0aea787..7f0cc42 100644 --- a/migrations/20250802154952_init.sql +++ b/migrations/20250802154952_init.sql @@ -1,12 +1,6 @@ -- +goose Up -- +goose StatementBegin CREATE TABLE user (id INTEGER PRIMARY KEY, username TEXT UNIQUE NOT NULL, email TEXT UNIQUE, password TEXT NOT NULL); -PRAGMA foreign_keys = ON; -PRAGMA journal_mode = WAL; -PRAGMA synchronous = NORMAL; -PRAGMA mmap_size = 134217728; -- 128 megabytes -PRAGMA journal_size_limig = 67108864; -- 64 megabytes -PRAGMA cache_size = 2000; -- +goose StatementEnd -- +goose Down diff --git a/pages/index.md b/pages/index.md index 413804b..caa86e2 100644 --- a/pages/index.md +++ b/pages/index.md @@ -68,6 +68,8 @@ Once you have that you can make it your own: git init . go mod tidy cp config_example.toml config.toml +make migrate +sqlite3 .\db.sqlite3 ".read tools/pragmas.sql" make dev ``` diff --git a/pages/layouts/main.html b/pages/layouts/main.html index 608d647..6576bce 100644 --- a/pages/layouts/main.html +++ b/pages/layouts/main.html @@ -8,11 +8,14 @@ + + + - ZedShaw.games + Go Web Dev Starter Kit - +
@@ -32,17 +49,25 @@ {{embed}} -