简化API节点的数据库配置(db.yaml)

This commit is contained in:
GoEdgeLab
2024-05-06 17:31:08 +08:00
parent 40ad9d2931
commit ff89e036d4
8 changed files with 159 additions and 80 deletions

View File

@@ -4,6 +4,7 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"github.com/TeaOSLab/EdgeAPI/internal/configs"
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
@@ -14,9 +15,7 @@ import (
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
stringutil "github.com/iwind/TeaGo/utils/string"
"gopkg.in/yaml.v3"
"io"
"os"
"time"
)
@@ -34,12 +33,7 @@ func NewSQLExecutor(dbConfig *dbs.DBConfig) *SQLExecutor {
func NewSQLExecutorFromCmd() (*SQLExecutor, error) {
// 执行SQL
var config = &dbs.Config{}
configData, err := os.ReadFile(Tea.ConfigFile("db.yaml"))
if err != nil {
return nil, err
}
err = yaml.Unmarshal(configData, config)
config, err := configs.LoadDBConfig()
if err != nil {
return nil, err
}
@@ -321,6 +315,9 @@ func (this *SQLExecutor) checkCluster(db *dbs.DB) error {
models.SharedNodeClusterDAO = models.NewNodeClusterDAO()
models.SharedNodeClusterDAO.Instance = db
models.SharedIPListDAO = models.NewIPListDAO()
models.SharedIPListDAO.Instance = db
policyId, err = models.SharedHTTPFirewallPolicyDAO.CreateDefaultFirewallPolicy(nil, "默认集群")
if err != nil {
return err