summaryrefslogtreecommitdiffhomepage
path: root/middleware
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-08-10 01:28:11 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-08-10 01:28:11 +0200
commit9d02dc16a8a0fc420fad36ed4c61bfcc3ea1518c (patch)
tree10f9994918081f08840bd4c1da642218f4b6c621 /middleware
parent32fcd6f170e8d8c77936d477f4e489f03d079375 (diff)
Do setting and theme toggling on the frontend
Diffstat (limited to 'middleware')
-rw-r--r--middleware/pipe.go14
-rw-r--r--middleware/theme.go42
2 files changed, 0 insertions, 56 deletions
diff --git a/middleware/pipe.go b/middleware/pipe.go
deleted file mode 100644
index 4b5064d..0000000
--- a/middleware/pipe.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package middleware
-
-import "net/http"
-
-type Middleware func(http.Handler) http.Handler
-
-func Pipe(xs ...Middleware) Middleware {
- return func(next http.Handler) http.Handler {
- for i := len(xs) - 1; i >= 0; i-- {
- next = xs[i](next)
- }
- return next
- }
-}
diff --git a/middleware/theme.go b/middleware/theme.go
deleted file mode 100644
index 4f14c97..0000000
--- a/middleware/theme.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package middleware
-
-import (
- "cmp"
- "context"
- "math"
- "net/http"
-)
-
-const defaultTheme = "dark"
-
-func Theme(next http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- var userTheme string
-
- /* Grab the ‘theme’ cookie to figure out what the users current
- theme is and add it to the context. If the user doesn’t yet
- have a theme cookie or the cookie they have contains an
- invalid theme then we fallback to the default theme and
- (re)set the cookie. */
-
- c, err := r.Cookie("theme")
- if err == nil {
- switch c.Value {
- case "dark", "light":
- userTheme = c.Value
- }
- }
-
- theme := cmp.Or(userTheme, defaultTheme)
- if userTheme == "" {
- http.SetCookie(w, &http.Cookie{
- Name: "theme",
- Value: theme,
- MaxAge: math.MaxInt32,
- })
- }
-
- ctx := context.WithValue(r.Context(), "theme", theme)
- next.ServeHTTP(w, r.WithContext(ctx))
- })
-}