mirror of
https://github.com/alireza0/x-ui.git
synced 2026-03-13 21:13:09 +00:00
45 lines
944 B
Go
45 lines
944 B
Go
package controller
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"x-ui/web/entity"
|
|
"x-ui/web/service"
|
|
)
|
|
|
|
type SettingController struct {
|
|
settingService service.SettingService
|
|
}
|
|
|
|
func NewSettingController(g *gin.RouterGroup) *SettingController {
|
|
a := &SettingController{}
|
|
a.initRouter(g)
|
|
return a
|
|
}
|
|
|
|
func (a *SettingController) initRouter(g *gin.RouterGroup) {
|
|
g = g.Group("/setting")
|
|
|
|
g.POST("/all", a.getAllSetting)
|
|
g.POST("/update", a.updateSetting)
|
|
}
|
|
|
|
func (a *SettingController) getAllSetting(c *gin.Context) {
|
|
allSetting, err := a.settingService.GetAllSetting()
|
|
if err != nil {
|
|
jsonMsg(c, "获取设置", err)
|
|
return
|
|
}
|
|
jsonObj(c, allSetting, nil)
|
|
}
|
|
|
|
func (a *SettingController) updateSetting(c *gin.Context) {
|
|
allSetting := &entity.AllSetting{}
|
|
err := c.ShouldBind(allSetting)
|
|
if err != nil {
|
|
jsonMsg(c, "修改设置", err)
|
|
return
|
|
}
|
|
err = a.settingService.UpdateAllSetting(allSetting)
|
|
jsonMsg(c, "修改设置", err)
|
|
}
|