diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-07 01:45:48 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-07 01:45:48 +0200 |
commit | e555accb612e189ab9bdad403958d4e0a6d809ae (patch) | |
tree | 319c4937a165a4b867a42f1852c3362ba577c68d /main.go | |
parent | 7fbaed9158ac5c405ee3150c2bf27af8ec1380ba (diff) |
Redirect the user after a language is set
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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) + } } |