summaryrefslogtreecommitdiffhomepage
path: root/main.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-08-07 01:45:48 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-08-07 01:45:48 +0200
commite555accb612e189ab9bdad403958d4e0a6d809ae (patch)
tree319c4937a165a4b867a42f1852c3362ba577c68d /main.go
parent7fbaed9158ac5c405ee3150c2bf27af8ec1380ba (diff)
Redirect the user after a language is set
Diffstat (limited to 'main.go')
-rw-r--r--main.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/main.go b/main.go
index ba475fd..6ecdf32 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,7 @@
package main
import (
- "context"
+ "errors"
"flag"
"fmt"
"log"
@@ -69,4 +69,14 @@ func setUserLanguage(w http.ResponseWriter, r *http.Request) {
Value: loc,
MaxAge: math.MaxInt32,
})
+
+ if c, err := r.Cookie("redirect"); errors.Is(err, http.ErrNoCookie) {
+ http.Redirect(w, r, "/", http.StatusFound)
+ } else {
+ http.SetCookie(w, &http.Cookie{
+ Name: "redirect",
+ MaxAge: -1,
+ })
+ http.Redirect(w, r, c.Value, http.StatusFound)
+ }
}