22 lines
478 B
Go
22 lines
478 B
Go
|
|
package admin
|
||
|
|
|
||
|
|
import (
|
||
|
|
"go_blog/themes"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
var themeManager = themes.NewManager("themes")
|
||
|
|
var router = gin.Default()
|
||
|
|
|
||
|
|
// 切换主题(管理后台)
|
||
|
|
func switchTheme(c *gin.Context) {
|
||
|
|
newTheme := c.PostForm("theme")
|
||
|
|
if err := themeManager.LoadTheme(newTheme); err != nil {
|
||
|
|
c.JSON(500, gin.H{"error": err.Error()})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
themeManager.RegisterStaticRoutes(router) // 重新注册静态路由
|
||
|
|
c.JSON(200, gin.H{"status": "success"})
|
||
|
|
}
|