-
Notifications
You must be signed in to change notification settings - Fork 487
/
Copy pathsettings.go
42 lines (34 loc) · 899 Bytes
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package system
import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/settings"
"github.com/gin-gonic/gin"
"net/http"
)
func GetSettings(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"server": settings.ServerSettings,
"nginx": settings.NginxSettings,
"openai": settings.OpenAISettings,
})
}
func SaveSettings(c *gin.Context) {
var json struct {
Server settings.Server `json:"server"`
Nginx settings.Nginx `json:"nginx"`
Openai settings.OpenAI `json:"openai"`
}
if !api.BindAndValid(c, &json) {
return
}
settings.ServerSettings = json.Server
settings.NginxSettings = json.Nginx
settings.OpenAISettings = json.Openai
settings.ReflectFrom()
err := settings.Save()
if err != nil {
api.ErrHandler(c, err)
return
}
GetSettings(c)
}