mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-05 16:50:34 +08:00
优化代码
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
//go:build plus
|
||||||
|
// +build plus
|
||||||
|
|
||||||
package accesslogs
|
package accesslogs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -5,7 +10,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
@@ -49,23 +53,6 @@ func (this *StorageManager) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 写入日志
|
|
||||||
func (this *StorageManager) Write(policyId int64, accessLogs []*pb.HTTPAccessLog) error {
|
|
||||||
this.locker.Lock()
|
|
||||||
storage, ok := this.storageMap[policyId]
|
|
||||||
this.locker.Unlock()
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !storage.IsOk() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return storage.Write(accessLogs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop 更新
|
// Loop 更新
|
||||||
func (this *StorageManager) Loop() error {
|
func (this *StorageManager) Loop() error {
|
||||||
policies, err := models.SharedHTTPAccessLogPolicyDAO.FindAllEnabledAndOnPolicies(nil)
|
policies, err := models.SharedHTTPAccessLogPolicyDAO.FindAllEnabledAndOnPolicies(nil)
|
||||||
|
|||||||
11
internal/accesslogs/storage_manager_write.go
Normal file
11
internal/accesslogs/storage_manager_write.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
//go:build community
|
||||||
|
// +build community
|
||||||
|
|
||||||
|
package accesslogs
|
||||||
|
|
||||||
|
// 写入日志
|
||||||
|
func (this *StorageManager) Write(policyId int64, accessLogs []*pb.HTTPAccessLog) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -93,16 +93,3 @@ func (this *AuthorityKeyDAO) ResetKey(tx *dbs.Tx) error {
|
|||||||
Delete()
|
Delete()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPlus 判断是否为企业版
|
|
||||||
func (this *AuthorityKeyDAO) IsPlus(tx *dbs.Tx) (bool, error) {
|
|
||||||
key, err := this.ReadKey(tx)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
if key == nil {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
teaconst.IsPlus = key.DayTo >= timeutil.Format("Y-m-d")
|
|
||||||
return teaconst.IsPlus, nil
|
|
||||||
}
|
|
||||||
|
|||||||
10
internal/db/models/authority/authority_key_dao_community.go
Normal file
10
internal/db/models/authority/authority_key_dao_community.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
//go:build community
|
||||||
|
// +build community
|
||||||
|
|
||||||
|
package authority
|
||||||
|
|
||||||
|
// IsPlus 判断是否为企业版
|
||||||
|
func (this *AuthorityKeyDAO) IsPlus(tx *dbs.Tx) (bool, error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
@@ -94,6 +95,10 @@ func (this *MessageTaskDAO) FindEnabledMessageTask(tx *dbs.Tx, id int64) (*Messa
|
|||||||
|
|
||||||
// CreateMessageTask 创建任务
|
// CreateMessageTask 创建任务
|
||||||
func (this *MessageTaskDAO) CreateMessageTask(tx *dbs.Tx, recipientId int64, instanceId int64, user string, subject string, body string, isPrimary bool) (int64, error) {
|
func (this *MessageTaskDAO) CreateMessageTask(tx *dbs.Tx, recipientId int64, instanceId int64, user string, subject string, body string, isPrimary bool) (int64, error) {
|
||||||
|
if !teaconst.IsPlus {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
var hash = stringutil.Md5(types.String(recipientId) + "@" + types.String(instanceId) + "@" + user + "@" + subject + "@" + types.String(isPrimary))
|
var hash = stringutil.Md5(types.String(recipientId) + "@" + types.String(instanceId) + "@" + user + "@" + subject + "@" + types.String(isPrimary))
|
||||||
recipientInstanceId, err := SharedMessageRecipientDAO.FindRecipientInstanceId(tx, recipientId)
|
recipientInstanceId, err := SharedMessageRecipientDAO.FindRecipientInstanceId(tx, recipientId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -196,6 +201,10 @@ func (this *MessageTaskDAO) UpdateMessageTaskStatus(tx *dbs.Tx, taskId int64, st
|
|||||||
|
|
||||||
// CreateMessageTasks 从集群、节点或者服务中创建任务
|
// CreateMessageTasks 从集群、节点或者服务中创建任务
|
||||||
func (this *MessageTaskDAO) CreateMessageTasks(tx *dbs.Tx, role nodeconfigs.NodeRole, clusterId int64, nodeId int64, serverId int64, messageType MessageType, subject string, body string) error {
|
func (this *MessageTaskDAO) CreateMessageTasks(tx *dbs.Tx, role nodeconfigs.NodeRole, clusterId int64, nodeId int64, serverId int64, messageType MessageType, subject string, body string) error {
|
||||||
|
if !teaconst.IsPlus {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
receivers, err := SharedMessageReceiverDAO.FindEnabledBestFitReceivers(tx, role, clusterId, nodeId, serverId, messageType)
|
receivers, err := SharedMessageReceiverDAO.FindEnabledBestFitReceivers(tx, role, clusterId, nodeId, serverId, messageType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user