实现自动清理服务访问日志

This commit is contained in:
GoEdgeLab
2021-01-19 12:05:35 +08:00
parent 8ea17ef75f
commit fa9dcc2f04
10 changed files with 188 additions and 18 deletions

13
internal/db/db_test.go Normal file
View File

@@ -0,0 +1,13 @@
package db
import (
"github.com/iwind/TeaGo/Tea"
_ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/dbs"
"testing"
)
func TestDB(t *testing.T) {
Tea.Env = "prod"
t.Log(dbs.Default())
}

View File

@@ -1 +1,17 @@
package models
import (
"fmt"
"github.com/iwind/TeaGo/dbs"
)
// 获取数据库配置
func (this *DBNode) DBConfig() *dbs.DBConfig {
dsn := this.Username + ":" + this.Password + "@tcp(" + this.Host + ":" + fmt.Sprintf("%d", this.Port) + ")/" + this.Database + "?charset=utf8mb4&timeout=10s"
return &dbs.DBConfig{
Driver: "mysql",
Dsn: dsn,
Prefix: "edge",
}
}

View File

@@ -4,6 +4,7 @@ import (
"github.com/TeaOSLab/EdgeAPI/internal/errors"
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ipconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
@@ -114,12 +115,12 @@ func (this *IPListDAO) UpdateIPList(tx *dbs.Tx, listId int64, name string, code
// 增加版本
func (this *IPListDAO) IncreaseVersion(tx *dbs.Tx) (int64, error) {
valueJSON, err := SharedSysSettingDAO.ReadSetting(tx, SettingCodeIPListVersion)
valueJSON, err := SharedSysSettingDAO.ReadSetting(tx, systemconfigs.SettingCodeIPListVersion)
if err != nil {
return 0, err
}
if len(valueJSON) == 0 {
err = SharedSysSettingDAO.UpdateSetting(tx, SettingCodeIPListVersion, []byte("1"))
err = SharedSysSettingDAO.UpdateSetting(tx, systemconfigs.SettingCodeIPListVersion, []byte("1"))
if err != nil {
return 0, err
}
@@ -127,7 +128,7 @@ func (this *IPListDAO) IncreaseVersion(tx *dbs.Tx) (int64, error) {
}
value := types.Int64(string(valueJSON)) + 1
err = SharedSysSettingDAO.UpdateSetting(tx, SettingCodeIPListVersion, []byte(numberutils.FormatInt64(value)))
err = SharedSysSettingDAO.UpdateSetting(tx, systemconfigs.SettingCodeIPListVersion, []byte(numberutils.FormatInt64(value)))
return value, nil
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
@@ -467,7 +468,7 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64) (*nodeconfigs.N
// 全局设置
// TODO 根据用户的不同读取不同的全局设置
settingJSON, err := SharedSysSettingDAO.ReadSetting(tx, SettingCodeServerGlobalConfig)
settingJSON, err := SharedSysSettingDAO.ReadSetting(tx, systemconfigs.SettingCodeServerGlobalConfig)
if err != nil {
return nil, err
}

View File

@@ -9,6 +9,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
@@ -295,7 +296,7 @@ func (this *ServerDAO) UpdateServerConfig(tx *dbs.Tx, serverId int64, configJSON
return false, err
}
globalConfig, err := SharedSysSettingDAO.ReadSetting(tx, SettingCodeServerGlobalConfig)
globalConfig, err := SharedSysSettingDAO.ReadSetting(tx, systemconfigs.SettingCodeServerGlobalConfig)
if err != nil {
return false, err
}

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
@@ -12,16 +13,6 @@ import (
type SysSettingDAO dbs.DAO
type SettingCode = string
const (
SettingCodeServerGlobalConfig SettingCode = "serverGlobalConfig" // 服务相关全局设置
SettingCodeNodeMonitor SettingCode = "nodeMonitor" // 监控节点状态
SettingCodeClusterHealthCheck SettingCode = "clusterHealthCheck" // 集群健康检查
SettingCodeIPListVersion SettingCode = "ipListVersion" // IP名单的版本号
SettingCodeAdminSecurityConfig SettingCode = "adminSecurityConfig" // 管理员安全设置
)
func NewSysSettingDAO() *SysSettingDAO {
return dbs.NewDAO(&SysSettingDAO{
DAOObject: dbs.DAOObject{
@@ -116,7 +107,7 @@ func (this *SysSettingDAO) CompareInt64Setting(tx *dbs.Tx, code string, anotherV
// 读取全局配置
func (this *SysSettingDAO) ReadGlobalConfig(tx *dbs.Tx) (*serverconfigs.GlobalConfig, error) {
globalConfigData, err := this.ReadSetting(tx, SettingCodeServerGlobalConfig)
globalConfigData, err := this.ReadSetting(tx, systemconfigs.SettingCodeServerGlobalConfig)
if err != nil {
return nil, err
}