-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_settings.go
77 lines (74 loc) · 1.92 KB
/
server_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"github.com/gin-gonic/gin"
"strings"
)
func serverAddSettings(root *gin.RouterGroup) {
root.GET("/settings", func(c *gin.Context) {
c.HTML(200, "settings.tmpl", gin.H{
"root": webroot,
"environment": config.Environment,
})
})
root.GET("/settings/:action/:section/:editkey", func(c *gin.Context) {
action := c.Param("action")
section := c.Param("section")
editkey := c.Param("editkey")
if action != "environment" {
c.HTML(404, "error.tmpl", gin.H{
"root": webroot,
"error": "cannot find page",
})
return
}
if editkey == "new" {
editkey = ""
}
var data map[string]string = nil
if action == "environment" {
data = config.Environment
}
c.HTML(200, "settings-edit.tmpl", gin.H{
"root": webroot,
"action": action,
"section": section,
"editkey": editkey,
"data": data,
})
})
root.POST("/settings", func(c *gin.Context) {
key := c.DefaultPostForm("key", "")
value := c.DefaultPostForm("value", "")
action := c.DefaultPostForm("action", "")
if action != "environment" {
c.HTML(404, "error.tmpl", gin.H{
"root": webroot,
"location": webroot + "settings",
"error": "invalid settings (Action)",
})
return
} else if action == "environment" {
editkey := c.DefaultPostForm("editkey", "")
subaction := c.DefaultPostForm("subaction", "")
editkey = strings.TrimSpace(editkey)
if editkey == "" && subaction != "new" {
c.HTML(404, "error.tmpl", gin.H{
"root": webroot,
"location": webroot + "settings",
"error": "invalid settings (Environment Variable)",
})
} else if subaction == "new" {
config.SetEnvironment(key, value)
} else if subaction == "delete" {
config.DelEnvironment(editkey)
} else {
if editkey != key {
config.DelEnvironment(editkey)
}
config.SetEnvironment(key, value)
}
}
config.Save()
c.Redirect(302, webroot+"settings")
})
}