diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-11 03:13:10 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-11 03:16:36 +0200 |
commit | 3273c65ef82123bf5edbe6d8616630b20a993ce1 (patch) | |
tree | d230d18f60122f3a1b65056df197ad1db0ca41b0 /middleware | |
parent | 3e723305c61673a767da25f683777de368899d41 (diff) |
Giant refactoring of the codebase
Diffstat (limited to 'middleware')
-rw-r--r-- | middleware/i18n.go | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/middleware/i18n.go b/middleware/i18n.go deleted file mode 100644 index 921534e..0000000 --- a/middleware/i18n.go +++ /dev/null @@ -1,42 +0,0 @@ -package middleware - -import ( - "cmp" - "context" - "errors" - "log" - "net/http" - "strings" - - "git.thomasvoss.com/euro-cash.eu/i18n" - "git.thomasvoss.com/euro-cash.eu/templates" -) - -func I18n(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var p, pZero i18n.Printer - - if c, err := r.Cookie("locale"); errors.Is(err, http.ErrNoCookie) { - log.Println("Language cookie not set") - } else { - var ok bool - p, ok = i18n.Printers[strings.ToLower(c.Value)] - if !ok { - log.Printf("Language ā%sā is unsupported\n", c.Value) - } - } - - ctx := context.WithValue( - r.Context(), "printer", cmp.Or(p, i18n.DefaultPrinter)) - - if p == pZero { - http.SetCookie(w, &http.Cookie{ - Name: "redirect", - Value: r.URL.Path, - }) - templates.Base(nil, templates.Language()).Render(ctx, w) - } else { - next.ServeHTTP(w, r.WithContext(ctx)) - } - }) -} |