实现访问日志队列

This commit is contained in:
GoEdgeLab
2021-12-14 12:45:09 +08:00
parent 37e1f21531
commit fffbba75d6
5 changed files with 144 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ func init() {
Data("teaSubMenu", "log").
Prefix("/servers/logs").
Get("", new(IndexAction)).
GetPost("/settings", new(SettingsAction)).
EndAll()
})
}

View File

@@ -0,0 +1,94 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package logs
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/actions"
)
type SettingsAction struct {
actionutils.ParentAction
}
func (this *SettingsAction) Init() {
this.Nav("", "", "settings")
}
func (this *SettingsAction) RunGet(params struct{}) {
settingsResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeAccessLogQueue})
if err != nil {
this.ErrorPage(err)
return
}
var config = &serverconfigs.AccessLogQueueConfig{
MaxLength: 0,
CountPerSecond: 0,
Percent: 100,
}
if len(settingsResp.ValueJSON) > 0 {
err = json.Unmarshal(settingsResp.ValueJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
} else {
configJSON, err := json.Marshal(config)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeAccessLogQueue,
ValueJSON: configJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
}
this.Data["config"] = config
this.Show()
}
func (this *SettingsAction) RunPost(params struct {
Percent int
CountPerSecond int
MaxLength int
Must *actions.Must
CSRF *actionutils.CSRF
}) {
params.Must.
Field("percent", params.Percent).
Gte(0, "请输入大于0的整数").
Lte(100, "请输入小于100的整数")
var config = &serverconfigs.AccessLogQueueConfig{
MaxLength: params.MaxLength,
CountPerSecond: params.CountPerSecond,
Percent: params.Percent,
}
configJSON, err := json.Marshal(config)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeAccessLogQueue,
ValueJSON: configJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}