diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 35 |
1 files changed, 1 insertions, 34 deletions
@@ -38,12 +38,8 @@ func main() { mux.Handle("GET /favicon.ico", fs) mux.Handle("GET /fonts/", fs) mux.Handle("GET /style.css", fs) - mux.Handle("GET /", middleware.Pipe( - middleware.Theme, - middleware.I18n, - )(http.HandlerFunc(finalHandler))) + mux.Handle("GET /", middleware.I18n(http.HandlerFunc(finalHandler))) mux.Handle("POST /language", http.HandlerFunc(setUserLanguage)) - mux.Handle("POST /theme", http.HandlerFunc(setUserTheme)) portStr := ":" + strconv.Itoa(*port) log.Println("Listening on", portStr) @@ -101,32 +97,3 @@ func setUserLanguage(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, c.Value, http.StatusFound) } } - -func setUserTheme(w http.ResponseWriter, r *http.Request) { - c, err := r.Cookie("theme") - if errors.Is(err, http.ErrNoCookie) { - w.WriteHeader(http.StatusBadRequest) - fmt.Fprintf(w, "No ‘theme’ cookie exists") - return - } - - var theme string - - switch c.Value { - case "dark": - theme = "light" - case "light": - theme = "dark" - default: - w.WriteHeader(http.StatusBadRequest) - fmt.Fprintf(w, "Theme ‘%s’ is invalid", c.Value) - return - } - - http.SetCookie(w, &http.Cookie{ - Name: "theme", - Value: theme, - MaxAge: math.MaxInt32, - }) - http.Redirect(w, r, r.Referer(), http.StatusFound) -} |