diff --git a/internal/db/db_test.go b/internal/db/db_test.go index f13cac9e..4b3db2bd 100644 --- a/internal/db/db_test.go +++ b/internal/db/db_test.go @@ -33,7 +33,7 @@ func TestDB_Instance(t *testing.T) { if err == driver.ErrBadConn { return } - t.Fatal(i, "exec:", err) + t.Error(i, "exec:", err) } time.Sleep(1 * time.Second) } diff --git a/internal/db/models/dns/dns_domain_dao.go b/internal/db/models/dns/dns_domain_dao.go index 69f2d33a..f35d3dba 100644 --- a/internal/db/models/dns/dns_domain_dao.go +++ b/internal/db/models/dns/dns_domain_dao.go @@ -218,6 +218,8 @@ func (this *DNSDomainDAO) ExistAvailableDomains(tx *dbs.Tx) (bool, error) { // ExistDomainRecord 检查域名解析记录是否存在 func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordName string, recordType string, recordRoute string, recordValue string) (bool, error) { + recordType = strings.ToUpper(recordType) + query := maps.Map{ "name": recordName, "type": recordType, @@ -239,7 +241,6 @@ func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordNa } } } - recordType = strings.ToUpper(recordType) return this.Query(tx). Pk(domainId). Where("JSON_CONTAINS(records, :query)"). diff --git a/internal/db/models/stats/server_client_browser_monthly_stat_dao_test.go b/internal/db/models/stats/server_client_browser_monthly_stat_dao_test.go index 5ee17ce9..c8074623 100644 --- a/internal/db/models/stats/server_client_browser_monthly_stat_dao_test.go +++ b/internal/db/models/stats/server_client_browser_monthly_stat_dao_test.go @@ -11,7 +11,7 @@ func TestServerClientBrowserMonthlyStatDAO_IncreaseMonthlyCount(t *testing.T) { dbs.NotifyReady() var tx *dbs.Tx - err := SharedServerClientBrowserMonthlyStatDAO.IncreaseMonthlyCount(tx, 1, 1, "202101", 1) + err := SharedServerClientBrowserMonthlyStatDAO.IncreaseMonthlyCount(tx, 1, 1, "1.0", "202101", 1) if err != nil { t.Fatal(err) } diff --git a/internal/db/models/stats/traffic_daily_stat_dao_test.go b/internal/db/models/stats/traffic_daily_stat_dao_test.go index eb2134bd..bdab4cfb 100644 --- a/internal/db/models/stats/traffic_daily_stat_dao_test.go +++ b/internal/db/models/stats/traffic_daily_stat_dao_test.go @@ -12,7 +12,7 @@ func TestTrafficDailyStatDAO_IncreaseDayBytes(t *testing.T) { dbs.NotifyReady() now := time.Now() - err := SharedTrafficDailyStatDAO.IncreaseDailyBytes(nil, timeutil.Format("Ymd"), 1) + err := SharedTrafficDailyStatDAO.IncreaseDailyStat(nil, timeutil.Format("Ymd"), 1, 1, 1, 1, 1, 1) if err != nil { t.Fatal(err) } diff --git a/internal/dnsclients/provider_huawei_dns.go b/internal/dnsclients/provider_huawei_dns.go index 283bcdcb..ba9d1105 100644 --- a/internal/dnsclients/provider_huawei_dns.go +++ b/internal/dnsclients/provider_huawei_dns.go @@ -1453,7 +1453,7 @@ func (this *HuaweiDNSProvider) doAPI(method string, apiPath string, args map[str req.Header.Set("x-sdk-date", datetime) req.Header.Set("Authorization", "SDK-HMAC-SHA256 Access="+this.accessKeyId+", SignedHeaders=content-type;host;x-sdk-date, Signature="+signString) - resp, err := cloudFlareHTTPClient.Do(req) + resp, err := huaweiDNSHTTPClient.Do(req) if err != nil { return err } diff --git a/internal/rpc/services/nameservers/service_ns_node.go b/internal/rpc/services/nameservers/service_ns_node.go index 0968ee98..261318aa 100644 --- a/internal/rpc/services/nameservers/service_ns_node.go +++ b/internal/rpc/services/nameservers/service_ns_node.go @@ -91,6 +91,9 @@ func (this *NSNodeService) ListEnabledNSNodesMatch(ctx context.Context, req *pb. var tx = this.NullTx() nodes, err := nameservers.SharedNSNodeDAO.ListAllEnabledNodesMatch(tx, req.NsClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.Offset, req.Size) + if err != nil { + return nil, err + } pbNodes := []*pb.NSNode{} for _, node := range nodes { // 安装信息 @@ -405,6 +408,9 @@ func (this *NSNodeService) DownloadNSNodeInstallationFile(ctx context.Context, r } data, offset, err := file.Read(req.ChunkOffset) + if err != nil { + return nil, err + } return &pb.DownloadNSNodeInstallationFileResponse{ Sum: sum, diff --git a/internal/setup/sql_dump.go b/internal/setup/sql_dump.go index 4f19c810..d8aa3a9b 100644 --- a/internal/setup/sql_dump.go +++ b/internal/setup/sql_dump.go @@ -305,7 +305,7 @@ func (this *SQLDump) tryCreateIndex(err error, db *dbs.DB, tableName string, ind } // 处理Duplicate entry - if strings.Index(err.Error(), "Error 1062: Duplicate entry") >= 0 && (strings.HasSuffix(tableName, "Stats") || strings.HasSuffix(tableName, "Values")) { + if strings.Contains(err.Error(), "Error 1062: Duplicate entry") && (strings.HasSuffix(tableName, "Stats") || strings.HasSuffix(tableName, "Values")) { var tries = 5 // 尝试次数 for i := 0; i < tries; i++ { _, err = db.Exec("TRUNCATE TABLE " + tableName) diff --git a/internal/setup/sql_executor.go b/internal/setup/sql_executor.go index c685b5f1..7f364528 100644 --- a/internal/setup/sql_executor.go +++ b/internal/setup/sql_executor.go @@ -16,7 +16,6 @@ import ( "github.com/iwind/TeaGo/types" stringutil "github.com/iwind/TeaGo/utils/string" "io/ioutil" - "strings" "time" ) @@ -279,7 +278,6 @@ func (this *SQLExecutor) checkMetricItems(db *dbs.DB) error { return err } - var itemId int64 = 0 if len(itemMap) == 0 { keysJSON, err := json.Marshal(keys) if err != nil { @@ -297,7 +295,7 @@ func (this *SQLExecutor) checkMetricItems(db *dbs.DB) error { } } - itemId = itemMap.GetInt64("id") + var itemId = itemMap.GetInt64("id") // chart for _, chartMap := range chartMaps { @@ -461,17 +459,3 @@ func (this *SQLExecutor) updateVersion(db *dbs.DB, version string) error { return nil } - -// 判断某个错误是否可以忽略 -func (this *SQLExecutor) canIgnoreError(err error) bool { - if err == nil { - return true - } - - // Error 1050: Table 'xxx' already exists - if strings.Contains(err.Error(), "Error 1050") { - return true - } - - return false -}