mirror of
https://github.com/keven1024/015.git
synced 2026-06-02 10:29:35 +00:00
feat(backend): add About and Config controllers for dynamic environment variable retrieval
This commit is contained in:
19
backend/internal/controllers/about.go
Normal file
19
backend/internal/controllers/about.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func GetAbout(c echo.Context) error {
|
||||
|
||||
return utils.HTTPSuccessHandler(c, map[string]any{
|
||||
"bg_url": utils.GetEnv("about.bg_url"),
|
||||
"content": utils.GetEnvMapString("about.content"),
|
||||
"email": utils.GetEnv("about.email"),
|
||||
"name": utils.GetEnv("about.name"),
|
||||
"url": utils.GetEnv("about.url"),
|
||||
"avatar": utils.GetEnv("about.avatar"),
|
||||
})
|
||||
}
|
||||
17
backend/internal/controllers/config.go
Normal file
17
backend/internal/controllers/config.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func GetConfig(c echo.Context) error {
|
||||
return utils.HTTPSuccessHandler(c, map[string]any{
|
||||
"site_title": utils.GetEnvMapString("site.title"),
|
||||
"site_desc": utils.GetEnvMapString("site.desc"),
|
||||
"site_url": utils.GetEnv("site.url"),
|
||||
"site_icon": utils.GetEnvWithDefault("site.icon", "/logo.png"),
|
||||
"site_bg_url": utils.GetEnvWithDefault("site.bg_url", "https://img.fudaoyuan.icu/api/1/random/?scale_min=1.5&webp=true&md=false&format=302"),
|
||||
})
|
||||
}
|
||||
@@ -44,3 +44,8 @@ func GetEnvWithDefault(key string, defaultValue string) string {
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func GetEnvMapString(key string) map[string]string {
|
||||
InitEnv()
|
||||
return v.GetStringMapString(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user