Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 97bbec4

Browse files
committed
[proxy]优化JavascriptAPI
1 parent 5cd2843 commit 97bbec4

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

teastats/counter_value.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package teastats
22

33
// 数值增长型的统计值
44
type CounterValue struct {
5-
Timestamp int64 `json:"timestamp"`
6-
Params map[string]string `json:"params"`
7-
Value map[string]interface{} `json:"value"`
5+
Timestamp int64 `json:"timestamp"` // 时间戳
6+
Params map[string]string `json:"params"` // 参数,用来区分单个统计项内的不同的项目
7+
Value map[string]interface{} `json:"value"` // 数值
88
}

teaweb/actions/default/proxy/board/scripts/engine.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (this *Engine) SetContext(context *Context) {
8383
"isDown": backend.IsDown,
8484
"isBackup": backend.IsBackup,
8585
"address": backend.Address,
86+
"code": backend.Code,
8687
}
8788
}),
8889
"locations": lists.Map(context.Server.Locations, func(k int, v interface{}) interface{} {
@@ -116,6 +117,26 @@ func (this *Engine) SetContext(context *Context) {
116117
"root": location.Root,
117118
"index": location.Index,
118119
"headers": location.Headers,
120+
"backends": lists.Map(location.Backends, func(k int, v interface{}) interface{} {
121+
backend := v.(*teaconfigs.BackendConfig)
122+
123+
if runningServer != nil {
124+
runningBackend := runningServer.FindBackend(backend.Id)
125+
if runningBackend != nil {
126+
backend.IsDown = runningBackend.IsDown
127+
}
128+
}
129+
130+
return map[string]interface{}{
131+
"isOn": backend.On,
132+
"weight": backend.Weight,
133+
"id": backend.Id,
134+
"isDown": backend.IsDown,
135+
"isBackup": backend.IsBackup,
136+
"address": backend.Address,
137+
"code": backend.Code,
138+
}
139+
}),
119140
}
120141
if location.Websocket != nil && location.Websocket.On {
121142
locationOptions["websocket"] = maps.Map{

0 commit comments

Comments
 (0)