54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package main
|
|
|
|
import "net/http"
|
|
|
|
type UserSettings struct {
|
|
Theme string
|
|
Language string
|
|
SafeSearch string
|
|
}
|
|
|
|
func loadUserSettings(r *http.Request) UserSettings {
|
|
var settings UserSettings
|
|
|
|
// Load theme
|
|
if cookie, err := r.Cookie("theme"); err == nil {
|
|
settings.Theme = cookie.Value
|
|
} else {
|
|
settings.Theme = "dark" // Default theme
|
|
}
|
|
|
|
// Load language
|
|
if cookie, err := r.Cookie("language"); err == nil {
|
|
settings.Language = cookie.Value
|
|
} else {
|
|
settings.Language = "en" // Default language
|
|
}
|
|
|
|
// Load safe search
|
|
if cookie, err := r.Cookie("safe"); err == nil {
|
|
settings.SafeSearch = cookie.Value
|
|
} else {
|
|
settings.SafeSearch = "" // Default safe search off
|
|
}
|
|
|
|
return settings
|
|
}
|
|
|
|
func saveUserSettings(w http.ResponseWriter, settings UserSettings) {
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: "theme",
|
|
Value: settings.Theme,
|
|
Path: "/",
|
|
})
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: "language",
|
|
Value: settings.Language,
|
|
Path: "/",
|
|
})
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: "safe",
|
|
Value: settings.SafeSearch,
|
|
Path: "/",
|
|
})
|
|
}
|