diff --git a/src/routes/home.go b/src/routes/home.go index 2d12e9d..e5120b4 100644 --- a/src/routes/home.go +++ b/src/routes/home.go @@ -2,6 +2,7 @@ package routes import ( "anonymousoverflow/config" + "anonymousoverflow/src/utils" "fmt" "os" "regexp" @@ -11,10 +12,7 @@ import ( ) func GetHome(c *gin.Context) { - theme := os.Getenv("THEME") - if theme == "" { - theme = "auto" - } + theme := utils.GetThemeFromEnv() c.HTML(200, "home.html", gin.H{ "version": config.Version, "theme": theme, diff --git a/src/routes/options.go b/src/routes/options.go index 9d91e64..4787eca 100644 --- a/src/routes/options.go +++ b/src/routes/options.go @@ -2,10 +2,8 @@ package routes import ( "anonymousoverflow/config" + "anonymousoverflow/src/utils" "fmt" - "os" - - "github.com/gin-gonic/gin" ) func ChangeOptions(c *gin.Context) { @@ -18,10 +16,7 @@ func ChangeOptions(c *gin.Context) { text = "enabled" } c.SetCookie("disable_images", fmt.Sprintf("%t", !c.MustGet("disable_images").(bool)), 60*60*24*365*10, "/", "", false, true) - theme := os.Getenv("THEME") - if theme == "" { - theme = "auto" - } + theme := utils.GetThemeFromEnv() c.HTML(200, "home.html", gin.H{ "successMessage": "Images are now " + text, "version": config.Version, diff --git a/src/routes/question.go b/src/routes/question.go index a7e1a3c..3b6274b 100644 --- a/src/routes/question.go +++ b/src/routes/question.go @@ -101,10 +101,7 @@ func ViewQuestion(c *gin.Context) { imagePolicy = "'self'" } - theme := os.Getenv("THEME") - if theme == "" { - theme = "auto" - } + theme := utils.GetThemeFromEnv() c.HTML(200, "question.html", gin.H{ "question": newFilteredQuestion, diff --git a/src/utils/theme.go b/src/utils/theme.go new file mode 100644 index 0000000..b78d9c4 --- /dev/null +++ b/src/utils/theme.go @@ -0,0 +1,11 @@ +package utils + +import "os" + +func GetThemeFromEnv() string { + theme := os.Getenv("THEME") + if theme == "" { + theme = "auto" + } + return theme +}