-
Notifications
You must be signed in to change notification settings - Fork 34
/
add.go
80 lines (67 loc) · 1.68 KB
/
add.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
78
79
80
package headers
import (
"github.com/TeaWeb/code/teaconfigs"
"github.com/TeaWeb/code/teaconfigs/shared"
"github.com/TeaWeb/code/teaweb/actions/default/proxy/proxyutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type AddAction actions.Action
// 添加Header
func (this *AddAction) Run(params struct {
From string
ServerId string
LocationId string
RewriteId string
FastcgiId string
BackendId string
}) {
this.Data["from"] = params.From
this.Data["server"] = maps.Map{
"id": params.ServerId,
}
this.Data["locationId"] = params.LocationId
this.Data["rewriteId"] = params.RewriteId
this.Data["fastcgiId"] = params.FastcgiId
this.Data["backendId"] = params.BackendId
this.Show()
}
// 提交保存
func (this *AddAction) RunPost(params struct {
ServerId string
LocationId string
RewriteId string
FastcgiId string
BackendId string
On bool
Name string
Value string
AllStatus bool
StatusList []int
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入名称")
server := teaconfigs.NewServerConfigFromId(params.ServerId)
if server == nil {
this.Fail("找不到Server")
}
headerList, err := server.FindHeaderList(params.LocationId, params.BackendId, params.RewriteId, params.FastcgiId)
if err != nil {
this.Fail(err.Error())
}
header := shared.NewHeaderConfig()
header.On = params.On
header.Name = params.Name
header.Value = params.Value
header.Always = params.AllStatus
header.Status = params.StatusList
headerList.AddResponseHeader(header)
err = server.Save()
if err != nil {
this.Fail("保存失败:" + err.Error())
}
proxyutils.NotifyChange()
this.Success()
}