mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
实现访问日志队列
This commit is contained in:
@@ -16,6 +16,7 @@ func init() {
|
||||
Data("teaSubMenu", "log").
|
||||
Prefix("/servers/logs").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/settings", new(SettingsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
94
internal/web/actions/default/servers/logs/settings.go
Normal file
94
internal/web/actions/default/servers/logs/settings.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user