管理端全部功能跑通
This commit is contained in:
101
EdgeAPI/internal/db/models/httpdns_access_log_dao.go
Normal file
101
EdgeAPI/internal/db/models/httpdns_access_log_dao.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
type HTTPDNSAccessLogDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSAccessLogDAO() *HTTPDNSAccessLogDAO {
|
||||
return dbs.NewDAO(&HTTPDNSAccessLogDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSAccessLogs",
|
||||
Model: new(HTTPDNSAccessLog),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSAccessLogDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSAccessLogDAO *HTTPDNSAccessLogDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSAccessLogDAO = NewHTTPDNSAccessLogDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) CreateLog(tx *dbs.Tx, log *HTTPDNSAccessLog) error {
|
||||
var op = NewHTTPDNSAccessLogOperator()
|
||||
op.RequestId = log.RequestId
|
||||
op.ClusterId = log.ClusterId
|
||||
op.NodeId = log.NodeId
|
||||
op.AppId = log.AppId
|
||||
op.AppName = log.AppName
|
||||
op.Domain = log.Domain
|
||||
op.QType = log.QType
|
||||
op.ClientIP = log.ClientIP
|
||||
op.ClientRegion = log.ClientRegion
|
||||
op.Carrier = log.Carrier
|
||||
op.SDKVersion = log.SDKVersion
|
||||
op.OS = log.OS
|
||||
op.ResultIPs = log.ResultIPs
|
||||
op.Status = log.Status
|
||||
op.ErrorCode = log.ErrorCode
|
||||
op.CostMs = log.CostMs
|
||||
op.CreatedAt = log.CreatedAt
|
||||
op.Day = log.Day
|
||||
op.Summary = log.Summary
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) BuildListQuery(tx *dbs.Tx, day string, clusterId int64, nodeId int64, appId string, domain string, status string, keyword string) *dbs.Query {
|
||||
query := this.Query(tx).DescPk()
|
||||
if len(day) > 0 {
|
||||
query = query.Attr("day", day)
|
||||
}
|
||||
if clusterId > 0 {
|
||||
query = query.Attr("clusterId", clusterId)
|
||||
}
|
||||
if nodeId > 0 {
|
||||
query = query.Attr("nodeId", nodeId)
|
||||
}
|
||||
if len(appId) > 0 {
|
||||
query = query.Attr("appId", appId)
|
||||
}
|
||||
if len(domain) > 0 {
|
||||
query = query.Attr("domain", domain)
|
||||
}
|
||||
if len(status) > 0 {
|
||||
query = query.Attr("status", status)
|
||||
}
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(summary LIKE :kw OR appName LIKE :kw OR clientIP LIKE :kw OR resultIPs LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) CountLogs(tx *dbs.Tx, day string, clusterId int64, nodeId int64, appId string, domain string, status string, keyword string) (int64, error) {
|
||||
return this.BuildListQuery(tx, day, clusterId, nodeId, appId, domain, status, keyword).Count()
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) ListLogs(tx *dbs.Tx, day string, clusterId int64, nodeId int64, appId string, domain string, status string, keyword string, offset int64, size int64) (result []*HTTPDNSAccessLog, err error) {
|
||||
_, err = this.BuildListQuery(tx, day, clusterId, nodeId, appId, domain, status, keyword).
|
||||
Offset(offset).
|
||||
Limit(size).
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAccessLogDAO) DeleteLogsWithAppId(tx *dbs.Tx, appId string) error {
|
||||
if len(appId) == 0 {
|
||||
return nil
|
||||
}
|
||||
_, err := this.Query(tx).
|
||||
Attr("appId", appId).
|
||||
Delete()
|
||||
return err
|
||||
}
|
||||
52
EdgeAPI/internal/db/models/httpdns_access_log_model.go
Normal file
52
EdgeAPI/internal/db/models/httpdns_access_log_model.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package models
|
||||
|
||||
// HTTPDNSAccessLog 访问日志
|
||||
type HTTPDNSAccessLog struct {
|
||||
Id uint64 `field:"id"` // ID
|
||||
RequestId string `field:"requestId"` // 请求ID
|
||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||
AppId string `field:"appId"` // AppID
|
||||
AppName string `field:"appName"` // 应用名
|
||||
Domain string `field:"domain"` // 域名
|
||||
QType string `field:"qtype"` // 查询类型
|
||||
ClientIP string `field:"clientIP"` // 客户端IP
|
||||
ClientRegion string `field:"clientRegion"` // 客户端区域
|
||||
Carrier string `field:"carrier"` // 运营商
|
||||
SDKVersion string `field:"sdkVersion"` // SDK版本
|
||||
OS string `field:"os"` // 系统
|
||||
ResultIPs string `field:"resultIPs"` // 结果IP
|
||||
Status string `field:"status"` // 状态
|
||||
ErrorCode string `field:"errorCode"` // 错误码
|
||||
CostMs int32 `field:"costMs"` // 耗时
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Day string `field:"day"` // YYYYMMDD
|
||||
Summary string `field:"summary"` // 概要
|
||||
}
|
||||
|
||||
type HTTPDNSAccessLogOperator struct {
|
||||
Id any // ID
|
||||
RequestId any // 请求ID
|
||||
ClusterId any // 集群ID
|
||||
NodeId any // 节点ID
|
||||
AppId any // AppID
|
||||
AppName any // 应用名
|
||||
Domain any // 域名
|
||||
QType any // 查询类型
|
||||
ClientIP any // 客户端IP
|
||||
ClientRegion any // 客户端区域
|
||||
Carrier any // 运营商
|
||||
SDKVersion any // SDK版本
|
||||
OS any // 系统
|
||||
ResultIPs any // 结果IP
|
||||
Status any // 状态
|
||||
ErrorCode any // 错误码
|
||||
CostMs any // 耗时
|
||||
CreatedAt any // 创建时间
|
||||
Day any // YYYYMMDD
|
||||
Summary any // 概要
|
||||
}
|
||||
|
||||
func NewHTTPDNSAccessLogOperator() *HTTPDNSAccessLogOperator {
|
||||
return &HTTPDNSAccessLogOperator{}
|
||||
}
|
||||
128
EdgeAPI/internal/db/models/httpdns_app_dao.go
Normal file
128
EdgeAPI/internal/db/models/httpdns_app_dao.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSAppStateEnabled = 1
|
||||
HTTPDNSAppStateDisabled = 0
|
||||
HTTPDNSSNIModeFixedHide = "fixed_hide"
|
||||
)
|
||||
|
||||
type HTTPDNSAppDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSAppDAO() *HTTPDNSAppDAO {
|
||||
return dbs.NewDAO(&HTTPDNSAppDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSApps",
|
||||
Model: new(HTTPDNSApp),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSAppDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSAppDAO *HTTPDNSAppDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSAppDAO = NewHTTPDNSAppDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) CreateApp(tx *dbs.Tx, name string, appId string, primaryClusterId int64, backupClusterId int64, isOn bool, userId int64) (int64, error) {
|
||||
var op = NewHTTPDNSAppOperator()
|
||||
op.Name = name
|
||||
op.AppId = appId
|
||||
op.PrimaryClusterId = primaryClusterId
|
||||
op.BackupClusterId = backupClusterId
|
||||
op.IsOn = isOn
|
||||
op.UserId = userId
|
||||
op.SNIMode = HTTPDNSSNIModeFixedHide
|
||||
op.CreatedAt = time.Now().Unix()
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
op.State = HTTPDNSAppStateEnabled
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) UpdateApp(tx *dbs.Tx, appDbId int64, name string, primaryClusterId int64, backupClusterId int64, isOn bool, userId int64) error {
|
||||
var op = NewHTTPDNSAppOperator()
|
||||
op.Id = appDbId
|
||||
op.Name = name
|
||||
op.PrimaryClusterId = primaryClusterId
|
||||
op.BackupClusterId = backupClusterId
|
||||
op.IsOn = isOn
|
||||
op.UserId = userId
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) DisableApp(tx *dbs.Tx, appDbId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(appDbId).
|
||||
Set("state", HTTPDNSAppStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) FindEnabledApp(tx *dbs.Tx, appDbId int64) (*HTTPDNSApp, error) {
|
||||
one, err := this.Query(tx).
|
||||
Pk(appDbId).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSApp), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) FindEnabledAppWithAppId(tx *dbs.Tx, appId string) (*HTTPDNSApp, error) {
|
||||
one, err := this.Query(tx).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
Attr("appId", appId).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSApp), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) ListEnabledApps(tx *dbs.Tx, offset int64, size int64, keyword string) (result []*HTTPDNSApp, err error) {
|
||||
query := this.Query(tx).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
AscPk()
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(name LIKE :kw OR appId LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
if size > 0 {
|
||||
query = query.Offset(offset).Limit(size)
|
||||
}
|
||||
_, err = query.Slice(&result).FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) CountEnabledApps(tx *dbs.Tx, keyword string) (int64, error) {
|
||||
query := this.Query(tx).State(HTTPDNSAppStateEnabled)
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(name LIKE :kw OR appId LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
return query.Count()
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppDAO) FindAllEnabledApps(tx *dbs.Tx) (result []*HTTPDNSApp, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(HTTPDNSAppStateEnabled).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
36
EdgeAPI/internal/db/models/httpdns_app_model.go
Normal file
36
EdgeAPI/internal/db/models/httpdns_app_model.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
// HTTPDNSApp maps to edgeHTTPDNSApps.
|
||||
type HTTPDNSApp struct {
|
||||
Id uint32 `field:"id"` // id
|
||||
Name string `field:"name"` // app name
|
||||
AppId string `field:"appId"` // external app id
|
||||
IsOn bool `field:"isOn"` // enabled
|
||||
PrimaryClusterId uint32 `field:"primaryClusterId"` // primary cluster id
|
||||
BackupClusterId uint32 `field:"backupClusterId"` // backup cluster id
|
||||
SNIMode string `field:"sniMode"` // sni mode
|
||||
UserId int64 `field:"userId"` // owner user id
|
||||
CreatedAt uint64 `field:"createdAt"` // created unix ts
|
||||
UpdatedAt uint64 `field:"updatedAt"` // updated unix ts
|
||||
State uint8 `field:"state"` // state
|
||||
}
|
||||
|
||||
// HTTPDNSAppOperator is used by DAO save/update.
|
||||
type HTTPDNSAppOperator struct {
|
||||
Id any // id
|
||||
Name any // app name
|
||||
AppId any // external app id
|
||||
IsOn any // enabled
|
||||
PrimaryClusterId any // primary cluster id
|
||||
BackupClusterId any // backup cluster id
|
||||
SNIMode any // sni mode
|
||||
UserId any // owner user id
|
||||
CreatedAt any // created unix ts
|
||||
UpdatedAt any // updated unix ts
|
||||
State any // state
|
||||
}
|
||||
|
||||
func NewHTTPDNSAppOperator() *HTTPDNSAppOperator {
|
||||
return &HTTPDNSAppOperator{}
|
||||
}
|
||||
|
||||
125
EdgeAPI/internal/db/models/httpdns_app_secret_dao.go
Normal file
125
EdgeAPI/internal/db/models/httpdns_app_secret_dao.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSAppSecretStateEnabled = 1
|
||||
HTTPDNSAppSecretStateDisabled = 0
|
||||
)
|
||||
|
||||
type HTTPDNSAppSecretDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSAppSecretDAO() *HTTPDNSAppSecretDAO {
|
||||
return dbs.NewDAO(&HTTPDNSAppSecretDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSAppSecrets",
|
||||
Model: new(HTTPDNSAppSecret),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSAppSecretDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSAppSecretDAO *HTTPDNSAppSecretDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSAppSecretDAO = NewHTTPDNSAppSecretDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) InitAppSecret(tx *dbs.Tx, appDbId int64, signEnabled bool) (string, uint64, error) {
|
||||
signSecret := "ss_" + rands.HexString(12)
|
||||
now := uint64(time.Now().Unix())
|
||||
var op = NewHTTPDNSAppSecretOperator()
|
||||
op.AppId = appDbId
|
||||
op.SignEnabled = signEnabled
|
||||
op.SignSecret = signSecret
|
||||
op.SignUpdatedAt = now
|
||||
op.UpdatedAt = now
|
||||
op.State = HTTPDNSAppSecretStateEnabled
|
||||
err := this.Save(tx, op)
|
||||
return signSecret, now, err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) FindEnabledAppSecret(tx *dbs.Tx, appDbId int64) (*HTTPDNSAppSecret, error) {
|
||||
one, err := this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSAppSecretStateEnabled).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSAppSecret), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) UpdateSignEnabled(tx *dbs.Tx, appDbId int64, signEnabled bool) error {
|
||||
_, err := this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSAppSecretStateEnabled).
|
||||
Set("signEnabled", signEnabled).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) ResetSignSecret(tx *dbs.Tx, appDbId int64) (string, int64, error) {
|
||||
signSecret := "ss_" + rands.HexString(12)
|
||||
now := time.Now().Unix()
|
||||
_, err := this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSAppSecretStateEnabled).
|
||||
Set("signSecret", signSecret).
|
||||
Set("signUpdatedAt", now).
|
||||
Set("updatedAt", now).
|
||||
Update()
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
return signSecret, now, nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) FindSignEnabled(tx *dbs.Tx, appDbId int64) (bool, error) {
|
||||
one, err := this.FindEnabledAppSecret(tx, appDbId)
|
||||
if err != nil || one == nil {
|
||||
return false, err
|
||||
}
|
||||
return one.SignEnabled, nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) FindSignSecretWithAppDbId(tx *dbs.Tx, appDbId int64) (string, error) {
|
||||
return this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSAppSecretStateEnabled).
|
||||
Result("signSecret").
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) FindSignUpdatedAt(tx *dbs.Tx, appDbId int64) (int64, error) {
|
||||
col, err := this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSAppSecretStateEnabled).
|
||||
Result("signUpdatedAt").
|
||||
FindCol(nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(col), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSAppSecretDAO) DisableAppSecret(tx *dbs.Tx, appDbId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSAppSecretStateEnabled).
|
||||
Set("state", HTTPDNSAppSecretStateDisabled).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
26
EdgeAPI/internal/db/models/httpdns_app_secret_model.go
Normal file
26
EdgeAPI/internal/db/models/httpdns_app_secret_model.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
// HTTPDNSAppSecret 应用验签密钥配置
|
||||
type HTTPDNSAppSecret struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AppId uint32 `field:"appId"` // 应用DB ID
|
||||
SignEnabled bool `field:"signEnabled"` // 是否启用验签
|
||||
SignSecret string `field:"signSecret"` // 验签密钥(当前先明文存储)
|
||||
SignUpdatedAt uint64 `field:"signUpdatedAt"` // 验签密钥更新时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
State uint8 `field:"state"` // 记录状态
|
||||
}
|
||||
|
||||
type HTTPDNSAppSecretOperator struct {
|
||||
Id any // ID
|
||||
AppId any // 应用DB ID
|
||||
SignEnabled any // 是否启用验签
|
||||
SignSecret any // 验签密钥
|
||||
SignUpdatedAt any // 验签密钥更新时间
|
||||
UpdatedAt any // 修改时间
|
||||
State any // 记录状态
|
||||
}
|
||||
|
||||
func NewHTTPDNSAppSecretOperator() *HTTPDNSAppSecretOperator {
|
||||
return &HTTPDNSAppSecretOperator{}
|
||||
}
|
||||
169
EdgeAPI/internal/db/models/httpdns_cluster_dao.go
Normal file
169
EdgeAPI/internal/db/models/httpdns_cluster_dao.go
Normal file
@@ -0,0 +1,169 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSClusterStateEnabled = 1
|
||||
HTTPDNSClusterStateDisabled = 0
|
||||
)
|
||||
|
||||
type HTTPDNSClusterDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSClusterDAO() *HTTPDNSClusterDAO {
|
||||
return dbs.NewDAO(&HTTPDNSClusterDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSClusters",
|
||||
Model: new(HTTPDNSCluster),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSClusterDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSClusterDAO *HTTPDNSClusterDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSClusterDAO = NewHTTPDNSClusterDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) CreateCluster(tx *dbs.Tx, name string, serviceDomain string, defaultTTL int32, fallbackTimeoutMs int32, installDir string, tlsPolicyJSON []byte, isOn bool, isDefault bool) (int64, error) {
|
||||
if isDefault {
|
||||
err := this.Query(tx).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
Set("isDefault", false).
|
||||
UpdateQuickly()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
var op = NewHTTPDNSClusterOperator()
|
||||
op.Name = name
|
||||
op.ServiceDomain = serviceDomain
|
||||
op.DefaultTTL = defaultTTL
|
||||
op.FallbackTimeoutMs = fallbackTimeoutMs
|
||||
op.InstallDir = installDir
|
||||
op.IsOn = isOn
|
||||
op.IsDefault = isDefault
|
||||
op.CreatedAt = time.Now().Unix()
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
op.State = HTTPDNSClusterStateEnabled
|
||||
if len(tlsPolicyJSON) > 0 {
|
||||
op.TLSPolicy = tlsPolicyJSON
|
||||
}
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, serviceDomain string, defaultTTL int32, fallbackTimeoutMs int32, installDir string, tlsPolicyJSON []byte, isOn bool, isDefault bool) error {
|
||||
if isDefault {
|
||||
err := this.Query(tx).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
Neq("id", clusterId).
|
||||
Set("isDefault", false).
|
||||
UpdateQuickly()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var op = NewHTTPDNSClusterOperator()
|
||||
op.Id = clusterId
|
||||
op.Name = name
|
||||
op.ServiceDomain = serviceDomain
|
||||
op.DefaultTTL = defaultTTL
|
||||
op.FallbackTimeoutMs = fallbackTimeoutMs
|
||||
op.InstallDir = installDir
|
||||
op.IsOn = isOn
|
||||
op.IsDefault = isDefault
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
if len(tlsPolicyJSON) > 0 {
|
||||
op.TLSPolicy = tlsPolicyJSON
|
||||
}
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) DisableCluster(tx *dbs.Tx, clusterId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(clusterId).
|
||||
Set("state", HTTPDNSClusterStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) FindEnabledCluster(tx *dbs.Tx, clusterId int64) (*HTTPDNSCluster, error) {
|
||||
one, err := this.Query(tx).
|
||||
Pk(clusterId).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSCluster), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) FindEnabledClusterName(tx *dbs.Tx, clusterId int64) (string, error) {
|
||||
return this.Query(tx).
|
||||
Pk(clusterId).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
Result("name").
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) ListEnabledClusters(tx *dbs.Tx, offset int64, size int64, keyword string) (result []*HTTPDNSCluster, err error) {
|
||||
query := this.Query(tx).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
AscPk()
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(name LIKE :kw OR serviceDomain LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
if size > 0 {
|
||||
query = query.Offset(offset).Limit(size)
|
||||
}
|
||||
_, err = query.Slice(&result).FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) CountEnabledClusters(tx *dbs.Tx, keyword string) (int64, error) {
|
||||
query := this.Query(tx).State(HTTPDNSClusterStateEnabled)
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(name LIKE :kw OR serviceDomain LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
return query.Count()
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) FindAllEnabledClusters(tx *dbs.Tx) (result []*HTTPDNSCluster, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSClusterDAO) UpdateDefaultCluster(tx *dbs.Tx, clusterId int64) error {
|
||||
err := this.Query(tx).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
Set("isDefault", false).
|
||||
UpdateQuickly()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = this.Query(tx).
|
||||
Pk(clusterId).
|
||||
State(HTTPDNSClusterStateEnabled).
|
||||
Set("isDefault", true).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
38
EdgeAPI/internal/db/models/httpdns_cluster_model.go
Normal file
38
EdgeAPI/internal/db/models/httpdns_cluster_model.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package models
|
||||
|
||||
import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
// HTTPDNSCluster HTTPDNS集群
|
||||
type HTTPDNSCluster struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
Name string `field:"name"` // 集群名称
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
IsDefault bool `field:"isDefault"` // 默认集群
|
||||
ServiceDomain string `field:"serviceDomain"` // 服务域名
|
||||
DefaultTTL int32 `field:"defaultTTL"` // 默认TTL
|
||||
FallbackTimeoutMs int32 `field:"fallbackTimeoutMs"` // 降级超时
|
||||
InstallDir string `field:"installDir"` // 安装目录
|
||||
TLSPolicy dbs.JSON `field:"tlsPolicy"` // TLS策略
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
State uint8 `field:"state"` // 记录状态
|
||||
}
|
||||
|
||||
type HTTPDNSClusterOperator struct {
|
||||
Id any // ID
|
||||
Name any // 集群名称
|
||||
IsOn any // 是否启用
|
||||
IsDefault any // 默认集群
|
||||
ServiceDomain any // 服务域名
|
||||
DefaultTTL any // 默认TTL
|
||||
FallbackTimeoutMs any // 降级超时
|
||||
InstallDir any // 安装目录
|
||||
TLSPolicy any // TLS策略
|
||||
CreatedAt any // 创建时间
|
||||
UpdatedAt any // 修改时间
|
||||
State any // 记录状态
|
||||
}
|
||||
|
||||
func NewHTTPDNSClusterOperator() *HTTPDNSClusterOperator {
|
||||
return &HTTPDNSClusterOperator{}
|
||||
}
|
||||
143
EdgeAPI/internal/db/models/httpdns_custom_rule_dao.go
Normal file
143
EdgeAPI/internal/db/models/httpdns_custom_rule_dao.go
Normal file
@@ -0,0 +1,143 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSCustomRuleStateEnabled = 1
|
||||
HTTPDNSCustomRuleStateDisabled = 0
|
||||
)
|
||||
|
||||
type HTTPDNSCustomRuleDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSCustomRuleDAO() *HTTPDNSCustomRuleDAO {
|
||||
return dbs.NewDAO(&HTTPDNSCustomRuleDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSCustomRules",
|
||||
Model: new(HTTPDNSCustomRule),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSCustomRuleDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSCustomRuleDAO *HTTPDNSCustomRuleDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSCustomRuleDAO = NewHTTPDNSCustomRuleDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) CreateRule(tx *dbs.Tx, rule *HTTPDNSCustomRule) (int64, error) {
|
||||
var op = NewHTTPDNSCustomRuleOperator()
|
||||
op.AppId = rule.AppId
|
||||
op.DomainId = rule.DomainId
|
||||
op.RuleName = rule.RuleName
|
||||
op.LineScope = rule.LineScope
|
||||
op.LineCarrier = rule.LineCarrier
|
||||
op.LineRegion = rule.LineRegion
|
||||
op.LineProvince = rule.LineProvince
|
||||
op.LineContinent = rule.LineContinent
|
||||
op.LineCountry = rule.LineCountry
|
||||
op.TTL = rule.TTL
|
||||
op.IsOn = rule.IsOn
|
||||
op.Priority = rule.Priority
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
op.State = HTTPDNSCustomRuleStateEnabled
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) UpdateRule(tx *dbs.Tx, rule *HTTPDNSCustomRule) error {
|
||||
var op = NewHTTPDNSCustomRuleOperator()
|
||||
op.Id = rule.Id
|
||||
op.RuleName = rule.RuleName
|
||||
op.LineScope = rule.LineScope
|
||||
op.LineCarrier = rule.LineCarrier
|
||||
op.LineRegion = rule.LineRegion
|
||||
op.LineProvince = rule.LineProvince
|
||||
op.LineContinent = rule.LineContinent
|
||||
op.LineCountry = rule.LineCountry
|
||||
op.TTL = rule.TTL
|
||||
op.IsOn = rule.IsOn
|
||||
op.Priority = rule.Priority
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) DisableRule(tx *dbs.Tx, ruleId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(ruleId).
|
||||
Set("state", HTTPDNSCustomRuleStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) DisableRulesWithAppId(tx *dbs.Tx, appDbId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSCustomRuleStateEnabled).
|
||||
Set("state", HTTPDNSCustomRuleStateDisabled).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) UpdateRuleStatus(tx *dbs.Tx, ruleId int64, isOn bool) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(ruleId).
|
||||
State(HTTPDNSCustomRuleStateEnabled).
|
||||
Set("isOn", isOn).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) FindEnabledRule(tx *dbs.Tx, ruleId int64) (*HTTPDNSCustomRule, error) {
|
||||
one, err := this.Query(tx).
|
||||
Pk(ruleId).
|
||||
State(HTTPDNSCustomRuleStateEnabled).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSCustomRule), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) ListEnabledRulesWithDomainId(tx *dbs.Tx, domainId int64) (result []*HTTPDNSCustomRule, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(HTTPDNSCustomRuleStateEnabled).
|
||||
Attr("domainId", domainId).
|
||||
Asc("priority").
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) ListEnabledRulesWithAppId(tx *dbs.Tx, appDbId int64) (result []*HTTPDNSCustomRule, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(HTTPDNSCustomRuleStateEnabled).
|
||||
Attr("appId", appDbId).
|
||||
Asc("priority").
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleDAO) CountEnabledRulesWithDomainId(tx *dbs.Tx, domainId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPDNSCustomRuleStateEnabled).
|
||||
Attr("domainId", domainId).
|
||||
Count()
|
||||
}
|
||||
42
EdgeAPI/internal/db/models/httpdns_custom_rule_model.go
Normal file
42
EdgeAPI/internal/db/models/httpdns_custom_rule_model.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package models
|
||||
|
||||
// HTTPDNSCustomRule 自定义解析规则
|
||||
type HTTPDNSCustomRule struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AppId uint32 `field:"appId"` // 应用DB ID
|
||||
DomainId uint32 `field:"domainId"` // 域名ID
|
||||
RuleName string `field:"ruleName"` // 规则名称
|
||||
LineScope string `field:"lineScope"` // 线路范围
|
||||
LineCarrier string `field:"lineCarrier"` // 运营商
|
||||
LineRegion string `field:"lineRegion"` // 区域
|
||||
LineProvince string `field:"lineProvince"` // 省份
|
||||
LineContinent string `field:"lineContinent"` // 大洲
|
||||
LineCountry string `field:"lineCountry"` // 国家
|
||||
TTL int32 `field:"ttl"` // TTL
|
||||
IsOn bool `field:"isOn"` // 启用状态
|
||||
Priority int32 `field:"priority"` // 优先级
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
State uint8 `field:"state"` // 记录状态
|
||||
}
|
||||
|
||||
type HTTPDNSCustomRuleOperator struct {
|
||||
Id any // ID
|
||||
AppId any // 应用DB ID
|
||||
DomainId any // 域名ID
|
||||
RuleName any // 规则名称
|
||||
LineScope any // 线路范围
|
||||
LineCarrier any // 运营商
|
||||
LineRegion any // 区域
|
||||
LineProvince any // 省份
|
||||
LineContinent any // 大洲
|
||||
LineCountry any // 国家
|
||||
TTL any // TTL
|
||||
IsOn any // 启用状态
|
||||
Priority any // 优先级
|
||||
UpdatedAt any // 修改时间
|
||||
State any // 记录状态
|
||||
}
|
||||
|
||||
func NewHTTPDNSCustomRuleOperator() *HTTPDNSCustomRuleOperator {
|
||||
return &HTTPDNSCustomRuleOperator{}
|
||||
}
|
||||
69
EdgeAPI/internal/db/models/httpdns_custom_rule_record_dao.go
Normal file
69
EdgeAPI/internal/db/models/httpdns_custom_rule_record_dao.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSCustomRuleRecordStateEnabled = 1
|
||||
HTTPDNSCustomRuleRecordStateDisabled = 0
|
||||
)
|
||||
|
||||
type HTTPDNSCustomRuleRecordDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSCustomRuleRecordDAO() *HTTPDNSCustomRuleRecordDAO {
|
||||
return dbs.NewDAO(&HTTPDNSCustomRuleRecordDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSCustomRuleRecords",
|
||||
Model: new(HTTPDNSCustomRuleRecord),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSCustomRuleRecordDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSCustomRuleRecordDAO *HTTPDNSCustomRuleRecordDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSCustomRuleRecordDAO = NewHTTPDNSCustomRuleRecordDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleRecordDAO) CreateRecord(tx *dbs.Tx, ruleId int64, recordType string, recordValue string, weight int32, sort int32) (int64, error) {
|
||||
var op = NewHTTPDNSCustomRuleRecordOperator()
|
||||
op.RuleId = ruleId
|
||||
op.RecordType = recordType
|
||||
op.RecordValue = recordValue
|
||||
op.Weight = weight
|
||||
op.Sort = sort
|
||||
op.State = HTTPDNSCustomRuleRecordStateEnabled
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleRecordDAO) DisableRecordsWithRuleId(tx *dbs.Tx, ruleId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Attr("ruleId", ruleId).
|
||||
State(HTTPDNSCustomRuleRecordStateEnabled).
|
||||
Set("state", HTTPDNSCustomRuleRecordStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSCustomRuleRecordDAO) ListEnabledRecordsWithRuleId(tx *dbs.Tx, ruleId int64) (result []*HTTPDNSCustomRuleRecord, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(HTTPDNSCustomRuleRecordStateEnabled).
|
||||
Attr("ruleId", ruleId).
|
||||
Asc("sort").
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
// HTTPDNSCustomRuleRecord 自定义规则记录值
|
||||
type HTTPDNSCustomRuleRecord struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
RuleId uint32 `field:"ruleId"` // 规则ID
|
||||
RecordType string `field:"recordType"` // 记录类型
|
||||
RecordValue string `field:"recordValue"` // 记录值
|
||||
Weight int32 `field:"weight"` // 权重
|
||||
Sort int32 `field:"sort"` // 顺序
|
||||
State uint8 `field:"state"` // 记录状态
|
||||
}
|
||||
|
||||
type HTTPDNSCustomRuleRecordOperator struct {
|
||||
Id any // ID
|
||||
RuleId any // 规则ID
|
||||
RecordType any // 记录类型
|
||||
RecordValue any // 记录值
|
||||
Weight any // 权重
|
||||
Sort any // 顺序
|
||||
State any // 记录状态
|
||||
}
|
||||
|
||||
func NewHTTPDNSCustomRuleRecordOperator() *HTTPDNSCustomRuleRecordOperator {
|
||||
return &HTTPDNSCustomRuleRecordOperator{}
|
||||
}
|
||||
115
EdgeAPI/internal/db/models/httpdns_domain_dao.go
Normal file
115
EdgeAPI/internal/db/models/httpdns_domain_dao.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSDomainStateEnabled = 1
|
||||
HTTPDNSDomainStateDisabled = 0
|
||||
)
|
||||
|
||||
type HTTPDNSDomainDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSDomainDAO() *HTTPDNSDomainDAO {
|
||||
return dbs.NewDAO(&HTTPDNSDomainDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSDomains",
|
||||
Model: new(HTTPDNSDomain),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSDomainDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSDomainDAO *HTTPDNSDomainDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSDomainDAO = NewHTTPDNSDomainDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSDomainDAO) CreateDomain(tx *dbs.Tx, appDbId int64, domain string, isOn bool) (int64, error) {
|
||||
domain = strings.ToLower(strings.TrimSpace(domain))
|
||||
var op = NewHTTPDNSDomainOperator()
|
||||
op.AppId = appDbId
|
||||
op.Domain = domain
|
||||
op.IsOn = isOn
|
||||
op.CreatedAt = time.Now().Unix()
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
op.State = HTTPDNSDomainStateEnabled
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSDomainDAO) DisableDomain(tx *dbs.Tx, domainId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(domainId).
|
||||
Set("state", HTTPDNSDomainStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSDomainDAO) DisableDomainsWithAppId(tx *dbs.Tx, appDbId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Attr("appId", appDbId).
|
||||
State(HTTPDNSDomainStateEnabled).
|
||||
Set("state", HTTPDNSDomainStateDisabled).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSDomainDAO) UpdateDomainStatus(tx *dbs.Tx, domainId int64, isOn bool) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(domainId).
|
||||
State(HTTPDNSDomainStateEnabled).
|
||||
Set("isOn", isOn).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSDomainDAO) FindEnabledDomain(tx *dbs.Tx, domainId int64) (*HTTPDNSDomain, error) {
|
||||
one, err := this.Query(tx).
|
||||
Pk(domainId).
|
||||
State(HTTPDNSDomainStateEnabled).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSDomain), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSDomainDAO) FindEnabledDomainWithAppAndName(tx *dbs.Tx, appDbId int64, domain string) (*HTTPDNSDomain, error) {
|
||||
one, err := this.Query(tx).
|
||||
State(HTTPDNSDomainStateEnabled).
|
||||
Attr("appId", appDbId).
|
||||
Attr("domain", strings.ToLower(strings.TrimSpace(domain))).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSDomain), nil
|
||||
}
|
||||
|
||||
func (this *HTTPDNSDomainDAO) ListEnabledDomainsWithAppId(tx *dbs.Tx, appDbId int64, keyword string) (result []*HTTPDNSDomain, err error) {
|
||||
query := this.Query(tx).
|
||||
State(HTTPDNSDomainStateEnabled).
|
||||
Attr("appId", appDbId).
|
||||
AscPk()
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("domain LIKE :kw").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
_, err = query.Slice(&result).FindAll()
|
||||
return
|
||||
}
|
||||
26
EdgeAPI/internal/db/models/httpdns_domain_model.go
Normal file
26
EdgeAPI/internal/db/models/httpdns_domain_model.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
// HTTPDNSDomain 应用绑定域名
|
||||
type HTTPDNSDomain struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AppId uint32 `field:"appId"` // 应用DB ID
|
||||
Domain string `field:"domain"` // 业务域名
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
State uint8 `field:"state"` // 记录状态
|
||||
}
|
||||
|
||||
type HTTPDNSDomainOperator struct {
|
||||
Id any // ID
|
||||
AppId any // 应用DB ID
|
||||
Domain any // 业务域名
|
||||
IsOn any // 是否启用
|
||||
CreatedAt any // 创建时间
|
||||
UpdatedAt any // 修改时间
|
||||
State any // 记录状态
|
||||
}
|
||||
|
||||
func NewHTTPDNSDomainOperator() *HTTPDNSDomainOperator {
|
||||
return &HTTPDNSDomainOperator{}
|
||||
}
|
||||
273
EdgeAPI/internal/db/models/httpdns_node_dao.go
Normal file
273
EdgeAPI/internal/db/models/httpdns_node_dao.go
Normal file
@@ -0,0 +1,273 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPDNSNodeStateEnabled = 1 // 已启用
|
||||
HTTPDNSNodeStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type HTTPDNSNodeDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSNodeDAO() *HTTPDNSNodeDAO {
|
||||
return dbs.NewDAO(&HTTPDNSNodeDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSNodes",
|
||||
Model: new(HTTPDNSNode),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSNodeDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSNodeDAO *HTTPDNSNodeDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSNodeDAO = NewHTTPDNSNodeDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// FindEnabledNodeIdWithUniqueId 根据唯一ID获取启用中的HTTPDNS节点ID
|
||||
func (this *HTTPDNSNodeDAO) FindEnabledNodeIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Attr("uniqueId", uniqueId).
|
||||
Attr("state", HTTPDNSNodeStateEnabled).
|
||||
ResultPk().
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// CreateNode 创建节点
|
||||
func (this *HTTPDNSNodeDAO) CreateNode(tx *dbs.Tx, clusterId int64, name string, installDir string, isOn bool) (int64, error) {
|
||||
uniqueId := rands.HexString(32)
|
||||
secret := rands.String(32)
|
||||
err := SharedApiTokenDAO.CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleHTTPDNS)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var op = NewHTTPDNSNodeOperator()
|
||||
op.ClusterId = clusterId
|
||||
op.Name = name
|
||||
op.IsOn = isOn
|
||||
op.IsUp = false
|
||||
op.IsInstalled = false
|
||||
op.IsActive = false
|
||||
op.UniqueId = uniqueId
|
||||
op.Secret = secret
|
||||
op.InstallDir = installDir
|
||||
op.CreatedAt = time.Now().Unix()
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
op.State = HTTPDNSNodeStateEnabled
|
||||
err = this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// UpdateNode 更新节点
|
||||
func (this *HTTPDNSNodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, installDir string, isOn bool) error {
|
||||
var op = NewHTTPDNSNodeOperator()
|
||||
op.Id = nodeId
|
||||
op.Name = name
|
||||
op.InstallDir = installDir
|
||||
op.IsOn = isOn
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
// DisableNode 禁用节点
|
||||
func (this *HTTPDNSNodeDAO) DisableNode(tx *dbs.Tx, nodeId int64) error {
|
||||
node, err := this.FindEnabledNode(tx, nodeId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if node == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = this.Query(tx).
|
||||
Pk(nodeId).
|
||||
Set("state", HTTPDNSNodeStateDisabled).
|
||||
Update()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = SharedApiTokenDAO.Query(tx).
|
||||
Attr("nodeId", node.UniqueId).
|
||||
Attr("role", nodeconfigs.NodeRoleHTTPDNS).
|
||||
Set("state", ApiTokenStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// FindEnabledNode 查找启用节点
|
||||
func (this *HTTPDNSNodeDAO) FindEnabledNode(tx *dbs.Tx, nodeId int64) (*HTTPDNSNode, error) {
|
||||
one, err := this.Query(tx).
|
||||
Pk(nodeId).
|
||||
Attr("state", HTTPDNSNodeStateEnabled).
|
||||
Find()
|
||||
if one == nil {
|
||||
return nil, err
|
||||
}
|
||||
return one.(*HTTPDNSNode), nil
|
||||
}
|
||||
|
||||
// FindNodeClusterId 查询节点所属集群ID
|
||||
func (this *HTTPDNSNodeDAO) FindNodeClusterId(tx *dbs.Tx, nodeId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Pk(nodeId).
|
||||
Attr("state", HTTPDNSNodeStateEnabled).
|
||||
Result("clusterId").
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// ListEnabledNodes 列出节点
|
||||
func (this *HTTPDNSNodeDAO) ListEnabledNodes(tx *dbs.Tx, clusterId int64) (result []*HTTPDNSNode, err error) {
|
||||
query := this.Query(tx).
|
||||
State(HTTPDNSNodeStateEnabled).
|
||||
AscPk()
|
||||
if clusterId > 0 {
|
||||
query = query.Attr("clusterId", clusterId)
|
||||
}
|
||||
_, err = query.Slice(&result).FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateNodeStatus 更新节点状态
|
||||
func (this *HTTPDNSNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, isUp bool, isInstalled bool, isActive bool, statusJSON []byte, installStatusJSON []byte) error {
|
||||
var op = NewHTTPDNSNodeOperator()
|
||||
op.Id = nodeId
|
||||
op.IsUp = isUp
|
||||
op.IsInstalled = isInstalled
|
||||
op.IsActive = isActive
|
||||
op.UpdatedAt = time.Now().Unix()
|
||||
if len(statusJSON) > 0 {
|
||||
op.Status = statusJSON
|
||||
}
|
||||
if len(installStatusJSON) > 0 {
|
||||
mergedStatusJSON, mergeErr := this.mergeInstallStatusJSON(tx, nodeId, installStatusJSON)
|
||||
if mergeErr != nil {
|
||||
return mergeErr
|
||||
}
|
||||
op.InstallStatus = mergedStatusJSON
|
||||
}
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
// UpdateNodeInstallStatus 更新节点安装状态
|
||||
func (this *HTTPDNSNodeDAO) UpdateNodeInstallStatus(tx *dbs.Tx, nodeId int64, installStatus *NodeInstallStatus) error {
|
||||
if installStatus == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Read existing installStatus to preserve custom fields like 'ssh' and 'ipAddr'
|
||||
raw, err := this.Query(tx).Pk(nodeId).Result("installStatus").FindBytesCol()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var m = map[string]interface{}{}
|
||||
if len(raw) > 0 {
|
||||
_ = json.Unmarshal(raw, &m)
|
||||
}
|
||||
|
||||
// Overlay standard install status fields
|
||||
statusData, err := json.Marshal(installStatus)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var newStatusMap = map[string]interface{}{}
|
||||
_ = json.Unmarshal(statusData, &newStatusMap)
|
||||
|
||||
for k, v := range newStatusMap {
|
||||
m[k] = v
|
||||
}
|
||||
|
||||
// Re-marshal the merged map
|
||||
mergedData, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = this.Query(tx).
|
||||
Pk(nodeId).
|
||||
Set("installStatus", mergedData).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *HTTPDNSNodeDAO) mergeInstallStatusJSON(tx *dbs.Tx, nodeId int64, patch []byte) ([]byte, error) {
|
||||
if len(patch) == 0 {
|
||||
return patch, nil
|
||||
}
|
||||
|
||||
raw, err := this.Query(tx).Pk(nodeId).Result("installStatus").FindBytesCol()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
merged := map[string]interface{}{}
|
||||
if len(raw) > 0 {
|
||||
_ = json.Unmarshal(raw, &merged)
|
||||
}
|
||||
patchMap := map[string]interface{}{}
|
||||
if len(patch) > 0 {
|
||||
_ = json.Unmarshal(patch, &patchMap)
|
||||
}
|
||||
|
||||
for k, v := range patchMap {
|
||||
merged[k] = v
|
||||
}
|
||||
|
||||
data, err := json.Marshal(merged)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// FindNodeInstallStatus 读取节点安装状态
|
||||
func (this *HTTPDNSNodeDAO) FindNodeInstallStatus(tx *dbs.Tx, nodeId int64) (*NodeInstallStatus, error) {
|
||||
raw, err := this.Query(tx).
|
||||
Pk(nodeId).
|
||||
State(HTTPDNSNodeStateEnabled).
|
||||
Result("installStatus").
|
||||
FindBytesCol()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(raw) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
installStatus := &NodeInstallStatus{}
|
||||
err = json.Unmarshal(raw, installStatus)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return installStatus, nil
|
||||
}
|
||||
|
||||
// UpdateNodeIsInstalled 更新节点安装状态位
|
||||
func (this *HTTPDNSNodeDAO) UpdateNodeIsInstalled(tx *dbs.Tx, nodeId int64, isInstalled bool) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(nodeId).
|
||||
State(HTTPDNSNodeStateEnabled).
|
||||
Set("isInstalled", isInstalled).
|
||||
Set("updatedAt", time.Now().Unix()).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
44
EdgeAPI/internal/db/models/httpdns_node_model.go
Normal file
44
EdgeAPI/internal/db/models/httpdns_node_model.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package models
|
||||
|
||||
import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
// HTTPDNSNode HTTPDNS节点
|
||||
type HTTPDNSNode struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||
Name string `field:"name"` // 节点名称
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
IsUp bool `field:"isUp"` // 是否在线
|
||||
IsInstalled bool `field:"isInstalled"` // 是否已安装
|
||||
IsActive bool `field:"isActive"` // 是否活跃
|
||||
UniqueId string `field:"uniqueId"` // 节点唯一ID
|
||||
Secret string `field:"secret"` // 节点密钥
|
||||
InstallDir string `field:"installDir"` // 安装目录
|
||||
Status dbs.JSON `field:"status"` // 运行状态快照
|
||||
InstallStatus dbs.JSON `field:"installStatus"` // 安装状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
State uint8 `field:"state"` // 记录状态
|
||||
}
|
||||
|
||||
type HTTPDNSNodeOperator struct {
|
||||
Id any // ID
|
||||
ClusterId any // 集群ID
|
||||
Name any // 节点名称
|
||||
IsOn any // 是否启用
|
||||
IsUp any // 是否在线
|
||||
IsInstalled any // 是否已安装
|
||||
IsActive any // 是否活跃
|
||||
UniqueId any // 节点唯一ID
|
||||
Secret any // 节点密钥
|
||||
InstallDir any // 安装目录
|
||||
Status any // 运行状态快照
|
||||
InstallStatus any // 安装状态
|
||||
CreatedAt any // 创建时间
|
||||
UpdatedAt any // 修改时间
|
||||
State any // 记录状态
|
||||
}
|
||||
|
||||
func NewHTTPDNSNodeOperator() *HTTPDNSNodeOperator {
|
||||
return &HTTPDNSNodeOperator{}
|
||||
}
|
||||
108
EdgeAPI/internal/db/models/httpdns_runtime_log_dao.go
Normal file
108
EdgeAPI/internal/db/models/httpdns_runtime_log_dao.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
type HTTPDNSRuntimeLogDAO dbs.DAO
|
||||
|
||||
func NewHTTPDNSRuntimeLogDAO() *HTTPDNSRuntimeLogDAO {
|
||||
return dbs.NewDAO(&HTTPDNSRuntimeLogDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPDNSRuntimeLogs",
|
||||
Model: new(HTTPDNSRuntimeLog),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPDNSRuntimeLogDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPDNSRuntimeLogDAO *HTTPDNSRuntimeLogDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPDNSRuntimeLogDAO = NewHTTPDNSRuntimeLogDAO()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *HTTPDNSRuntimeLogDAO) CreateLog(tx *dbs.Tx, log *HTTPDNSRuntimeLog) error {
|
||||
lastLog, err := this.Query(tx).
|
||||
Result("id", "clusterId", "nodeId", "level", "type", "module", "description", "createdAt").
|
||||
DescPk().
|
||||
Find()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if lastLog != nil {
|
||||
nodeLog := lastLog.(*HTTPDNSRuntimeLog)
|
||||
if nodeLog.ClusterId == log.ClusterId &&
|
||||
nodeLog.NodeId == log.NodeId &&
|
||||
nodeLog.Level == log.Level &&
|
||||
nodeLog.Type == log.Type &&
|
||||
nodeLog.Module == log.Module &&
|
||||
nodeLog.Description == log.Description &&
|
||||
time.Now().Unix()-int64(nodeLog.CreatedAt) < 1800 {
|
||||
|
||||
count := log.Count
|
||||
if count <= 0 {
|
||||
count = 1
|
||||
}
|
||||
|
||||
return this.Query(tx).
|
||||
Pk(nodeLog.Id).
|
||||
Set("count", dbs.SQL("count+"+strconv.FormatInt(count, 10))).
|
||||
UpdateQuickly()
|
||||
}
|
||||
}
|
||||
|
||||
var op = NewHTTPDNSRuntimeLogOperator()
|
||||
op.ClusterId = log.ClusterId
|
||||
op.NodeId = log.NodeId
|
||||
op.Level = log.Level
|
||||
op.Type = log.Type
|
||||
op.Module = log.Module
|
||||
op.Description = log.Description
|
||||
op.Count = log.Count
|
||||
op.RequestId = log.RequestId
|
||||
op.CreatedAt = log.CreatedAt
|
||||
op.Day = log.Day
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
func (this *HTTPDNSRuntimeLogDAO) BuildListQuery(tx *dbs.Tx, day string, clusterId int64, nodeId int64, level string, keyword string) *dbs.Query {
|
||||
query := this.Query(tx).DescPk()
|
||||
if len(day) > 0 {
|
||||
query = query.Attr("day", day)
|
||||
}
|
||||
if clusterId > 0 {
|
||||
query = query.Attr("clusterId", clusterId)
|
||||
}
|
||||
if nodeId > 0 {
|
||||
query = query.Attr("nodeId", nodeId)
|
||||
}
|
||||
if len(level) > 0 {
|
||||
query = query.Attr("level", level)
|
||||
}
|
||||
if len(keyword) > 0 {
|
||||
query = query.Where("(type LIKE :kw OR module LIKE :kw OR description LIKE :kw OR requestId LIKE :kw)").Param("kw", "%"+keyword+"%")
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
func (this *HTTPDNSRuntimeLogDAO) CountLogs(tx *dbs.Tx, day string, clusterId int64, nodeId int64, level string, keyword string) (int64, error) {
|
||||
return this.BuildListQuery(tx, day, clusterId, nodeId, level, keyword).Count()
|
||||
}
|
||||
|
||||
func (this *HTTPDNSRuntimeLogDAO) ListLogs(tx *dbs.Tx, day string, clusterId int64, nodeId int64, level string, keyword string, offset int64, size int64) (result []*HTTPDNSRuntimeLog, err error) {
|
||||
_, err = this.BuildListQuery(tx, day, clusterId, nodeId, level, keyword).
|
||||
Offset(offset).
|
||||
Limit(size).
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
34
EdgeAPI/internal/db/models/httpdns_runtime_log_model.go
Normal file
34
EdgeAPI/internal/db/models/httpdns_runtime_log_model.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package models
|
||||
|
||||
// HTTPDNSRuntimeLog 运行日志
|
||||
type HTTPDNSRuntimeLog struct {
|
||||
Id uint64 `field:"id"` // ID
|
||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||
Level string `field:"level"` // 级别
|
||||
Type string `field:"type"` // 类型
|
||||
Module string `field:"module"` // 模块
|
||||
Description string `field:"description"` // 详情
|
||||
Count int64 `field:"count"` // 次数
|
||||
RequestId string `field:"requestId"` // 请求ID
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Day string `field:"day"` // YYYYMMDD
|
||||
}
|
||||
|
||||
type HTTPDNSRuntimeLogOperator struct {
|
||||
Id any // ID
|
||||
ClusterId any // 集群ID
|
||||
NodeId any // 节点ID
|
||||
Level any // 级别
|
||||
Type any // 类型
|
||||
Module any // 模块
|
||||
Description any // 详情
|
||||
Count any // 次数
|
||||
RequestId any // 请求ID
|
||||
CreatedAt any // 创建时间
|
||||
Day any // YYYYMMDD
|
||||
}
|
||||
|
||||
func NewHTTPDNSRuntimeLogOperator() *HTTPDNSRuntimeLogOperator {
|
||||
return &HTTPDNSRuntimeLogOperator{}
|
||||
}
|
||||
@@ -15,35 +15,41 @@ import (
|
||||
type NodeTaskType = string
|
||||
|
||||
const (
|
||||
// CDN相关
|
||||
// CDN鐩稿叧
|
||||
|
||||
NodeTaskTypeConfigChanged NodeTaskType = "configChanged" // 节点整体配置变化
|
||||
NodeTaskTypeDDosProtectionChanged NodeTaskType = "ddosProtectionChanged" // 节点DDoS配置变更
|
||||
NodeTaskTypeGlobalServerConfigChanged NodeTaskType = "globalServerConfigChanged" // 全局服务设置变化
|
||||
NodeTaskTypeIPListDeleted NodeTaskType = "ipListDeleted" // IPList被删除
|
||||
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged" // IP条目变更
|
||||
NodeTaskTypeNodeVersionChanged NodeTaskType = "nodeVersionChanged" // 节点版本变化
|
||||
NodeTaskTypeScriptsChanged NodeTaskType = "scriptsChanged" // 脚本配置变化
|
||||
NodeTaskTypeNodeLevelChanged NodeTaskType = "nodeLevelChanged" // 节点级别变化
|
||||
NodeTaskTypeUserServersStateChanged NodeTaskType = "userServersStateChanged" // 用户服务状态变化
|
||||
NodeTaskTypeUAMPolicyChanged NodeTaskType = "uamPolicyChanged" // UAM策略变化
|
||||
NodeTaskTypeHTTPPagesPolicyChanged NodeTaskType = "httpPagesPolicyChanged" // 自定义页面变化
|
||||
NodeTaskTypeHTTPCCPolicyChanged NodeTaskType = "httpCCPolicyChanged" // CC策略变化
|
||||
NodeTaskTypeHTTP3PolicyChanged NodeTaskType = "http3PolicyChanged" // HTTP3策略变化
|
||||
NodeTaskTypeNetworkSecurityPolicyChanged NodeTaskType = "networkSecurityPolicyChanged" // 网络安全策略变化
|
||||
NodeTaskTypeWebPPolicyChanged NodeTaskType = "webPPolicyChanged" // WebP策略变化
|
||||
NodeTaskTypeUpdatingServers NodeTaskType = "updatingServers" // 更新一组服务
|
||||
NodeTaskTypeTOAChanged NodeTaskType = "toaChanged" // TOA配置变化
|
||||
NodeTaskTypePlanChanged NodeTaskType = "planChanged" // 套餐变化
|
||||
NodeTaskTypeConfigChanged NodeTaskType = "configChanged" // 鑺傜偣鏁翠綋閰嶇疆鍙樺寲
|
||||
NodeTaskTypeDDosProtectionChanged NodeTaskType = "ddosProtectionChanged" // 鑺傜偣DDoS閰嶇疆鍙樻洿
|
||||
NodeTaskTypeGlobalServerConfigChanged NodeTaskType = "globalServerConfigChanged" // 鍏ㄥ眬鏈嶅姟璁剧疆鍙樺寲
|
||||
NodeTaskTypeIPListDeleted NodeTaskType = "ipListDeleted" // IPList琚垹闄?
|
||||
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged" // IP鏉$洰鍙樻洿
|
||||
NodeTaskTypeNodeVersionChanged NodeTaskType = "nodeVersionChanged" // 鑺傜偣鐗堟湰鍙樺寲
|
||||
NodeTaskTypeScriptsChanged NodeTaskType = "scriptsChanged" // 鑴氭湰閰嶇疆鍙樺寲
|
||||
NodeTaskTypeNodeLevelChanged NodeTaskType = "nodeLevelChanged" // 鑺傜偣绾у埆鍙樺寲
|
||||
NodeTaskTypeUserServersStateChanged NodeTaskType = "userServersStateChanged" // 鐢ㄦ埛鏈嶅姟鐘舵€佸彉鍖?
|
||||
NodeTaskTypeUAMPolicyChanged NodeTaskType = "uamPolicyChanged" // UAM绛栫暐鍙樺寲
|
||||
NodeTaskTypeHTTPPagesPolicyChanged NodeTaskType = "httpPagesPolicyChanged" // 鑷畾涔夐〉闈㈠彉鍖?
|
||||
NodeTaskTypeHTTPCCPolicyChanged NodeTaskType = "httpCCPolicyChanged" // CC绛栫暐鍙樺寲
|
||||
NodeTaskTypeHTTP3PolicyChanged NodeTaskType = "http3PolicyChanged" // HTTP3绛栫暐鍙樺寲
|
||||
NodeTaskTypeNetworkSecurityPolicyChanged NodeTaskType = "networkSecurityPolicyChanged" // 缃戠粶瀹夊叏绛栫暐鍙樺寲
|
||||
NodeTaskTypeWebPPolicyChanged NodeTaskType = "webPPolicyChanged" // WebP绛栫暐鍙樺寲
|
||||
NodeTaskTypeUpdatingServers NodeTaskType = "updatingServers" // 鏇存柊涓€缁勬湇鍔?
|
||||
NodeTaskTypeTOAChanged NodeTaskType = "toaChanged" // TOA閰嶇疆鍙樺寲
|
||||
NodeTaskTypePlanChanged NodeTaskType = "planChanged" // 濂楅鍙樺寲
|
||||
|
||||
// NS相关
|
||||
// NS鐩稿叧
|
||||
|
||||
NSNodeTaskTypeConfigChanged NodeTaskType = "nsConfigChanged"
|
||||
NSNodeTaskTypeDomainChanged NodeTaskType = "nsDomainChanged"
|
||||
NSNodeTaskTypeRecordChanged NodeTaskType = "nsRecordChanged"
|
||||
NSNodeTaskTypeRouteChanged NodeTaskType = "nsRouteChanged"
|
||||
NSNodeTaskTypeKeyChanged NodeTaskType = "nsKeyChanged"
|
||||
NSNodeTaskTypeDDosProtectionChanged NodeTaskType = "nsDDoSProtectionChanged" // 节点DDoS配置变更
|
||||
NSNodeTaskTypeDDosProtectionChanged NodeTaskType = "nsDDoSProtectionChanged" // 鑺傜偣DDoS閰嶇疆鍙樻洿
|
||||
// HTTPDNS相关
|
||||
HTTPDNSNodeTaskTypeConfigChanged NodeTaskType = "httpdnsConfigChanged"
|
||||
HTTPDNSNodeTaskTypeAppChanged NodeTaskType = "httpdnsAppChanged"
|
||||
HTTPDNSNodeTaskTypeDomainChanged NodeTaskType = "httpdnsDomainChanged"
|
||||
HTTPDNSNodeTaskTypeRuleChanged NodeTaskType = "httpdnsRuleChanged"
|
||||
HTTPDNSNodeTaskTypeTLSChanged NodeTaskType = "httpdnsTLSChanged"
|
||||
)
|
||||
|
||||
type NodeTaskDAO dbs.DAO
|
||||
@@ -67,15 +73,15 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// CreateNodeTask 创建单个节点任务
|
||||
// CreateNodeTask 鍒涘缓鍗曚釜鑺傜偣浠诲姟
|
||||
func (this *NodeTaskDAO) CreateNodeTask(tx *dbs.Tx, role string, clusterId int64, nodeId int64, userId int64, serverId int64, taskType NodeTaskType) error {
|
||||
if clusterId <= 0 || nodeId <= 0 {
|
||||
return nil
|
||||
}
|
||||
var uniqueId = role + "@" + types.String(nodeId) + "@node@" + types.String(serverId) + "@" + taskType
|
||||
|
||||
// 用户信息
|
||||
// 没有直接加入到 uniqueId 中,是为了兼容以前的字段值
|
||||
// 鐢ㄦ埛淇℃伅
|
||||
// 娌℃湁鐩存帴鍔犲叆鍒?uniqueId 涓紝鏄负浜嗗吋瀹逛互鍓嶇殑瀛楁鍊?
|
||||
if userId > 0 {
|
||||
uniqueId += "@" + types.String(userId)
|
||||
}
|
||||
@@ -113,7 +119,7 @@ func (this *NodeTaskDAO) CreateNodeTask(tx *dbs.Tx, role string, clusterId int64
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateClusterTask 创建集群任务
|
||||
// CreateClusterTask 鍒涘缓闆嗙兢浠诲姟
|
||||
func (this *NodeTaskDAO) CreateClusterTask(tx *dbs.Tx, role string, clusterId int64, userId int64, serverId int64, taskType NodeTaskType) error {
|
||||
if clusterId <= 0 {
|
||||
return nil
|
||||
@@ -121,8 +127,8 @@ func (this *NodeTaskDAO) CreateClusterTask(tx *dbs.Tx, role string, clusterId in
|
||||
|
||||
var uniqueId = role + "@" + types.String(clusterId) + "@" + types.String(serverId) + "@cluster@" + taskType
|
||||
|
||||
// 用户信息
|
||||
// 没有直接加入到 uniqueId 中,是为了兼容以前的字段值
|
||||
// 鐢ㄦ埛淇℃伅
|
||||
// 娌℃湁鐩存帴鍔犲叆鍒?uniqueId 涓紝鏄负浜嗗吋瀹逛互鍓嶇殑瀛楁鍊?
|
||||
if userId > 0 {
|
||||
uniqueId += "@" + types.String(userId)
|
||||
}
|
||||
@@ -155,7 +161,7 @@ func (this *NodeTaskDAO) CreateClusterTask(tx *dbs.Tx, role string, clusterId in
|
||||
return err
|
||||
}
|
||||
|
||||
// ExtractNodeClusterTask 分解边缘节点集群任务
|
||||
// ExtractNodeClusterTask 鍒嗚В杈圭紭鑺傜偣闆嗙兢浠诲姟
|
||||
func (this *NodeTaskDAO) ExtractNodeClusterTask(tx *dbs.Tx, clusterId int64, userId int64, serverId int64, taskType NodeTaskType) error {
|
||||
nodeIds, err := SharedNodeDAO.FindAllNodeIdsMatch(tx, clusterId, true, configutils.BoolStateYes)
|
||||
if err != nil {
|
||||
@@ -193,7 +199,7 @@ func (this *NodeTaskDAO) ExtractNodeClusterTask(tx *dbs.Tx, clusterId int64, use
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExtractAllClusterTasks 分解所有集群任务
|
||||
// ExtractAllClusterTasks 鍒嗚В鎵€鏈夐泦缇や换鍔?
|
||||
func (this *NodeTaskDAO) ExtractAllClusterTasks(tx *dbs.Tx, role string) error {
|
||||
ones, err := this.Query(tx).
|
||||
Attr("role", role).
|
||||
@@ -216,12 +222,17 @@ func (this *NodeTaskDAO) ExtractAllClusterTasks(tx *dbs.Tx, role string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case nodeconfigs.NodeRoleHTTPDNS:
|
||||
err = this.ExtractHTTPDNSClusterTask(tx, clusterId, one.(*NodeTask).Type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteAllClusterTasks 删除集群所有相关任务
|
||||
// DeleteAllClusterTasks 鍒犻櫎闆嗙兢鎵€鏈夌浉鍏充换鍔?
|
||||
func (this *NodeTaskDAO) DeleteAllClusterTasks(tx *dbs.Tx, role string, clusterId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Attr("role", role).
|
||||
@@ -230,7 +241,7 @@ func (this *NodeTaskDAO) DeleteAllClusterTasks(tx *dbs.Tx, role string, clusterI
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteNodeTasks 删除节点相关任务
|
||||
// DeleteNodeTasks 鍒犻櫎鑺傜偣鐩稿叧浠诲姟
|
||||
func (this *NodeTaskDAO) DeleteNodeTasks(tx *dbs.Tx, role string, nodeId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Attr("role", role).
|
||||
@@ -239,13 +250,13 @@ func (this *NodeTaskDAO) DeleteNodeTasks(tx *dbs.Tx, role string, nodeId int64)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteAllNodeTasks 删除所有节点相关任务
|
||||
// DeleteAllNodeTasks 鍒犻櫎鎵€鏈夎妭鐐圭浉鍏充换鍔?
|
||||
func (this *NodeTaskDAO) DeleteAllNodeTasks(tx *dbs.Tx) error {
|
||||
return this.Query(tx).
|
||||
DeleteQuickly()
|
||||
}
|
||||
|
||||
// FindDoingNodeTasks 查询一个节点的所有任务
|
||||
// FindDoingNodeTasks 鏌ヨ涓€涓妭鐐圭殑鎵€鏈変换鍔?
|
||||
func (this *NodeTaskDAO) FindDoingNodeTasks(tx *dbs.Tx, role string, nodeId int64, version int64) (result []*NodeTask, err error) {
|
||||
if nodeId <= 0 {
|
||||
return
|
||||
@@ -256,10 +267,10 @@ func (this *NodeTaskDAO) FindDoingNodeTasks(tx *dbs.Tx, role string, nodeId int6
|
||||
UseIndex("nodeId").
|
||||
Asc("version")
|
||||
if version > 0 {
|
||||
query.Lt("LENGTH(version)", 19) // 兼容以往版本
|
||||
query.Lt("LENGTH(version)", 19) // 鍏煎浠ュ線鐗堟湰
|
||||
query.Gt("version", version)
|
||||
} else {
|
||||
// 第一次访问时只取当前正在执行的或者执行失败的
|
||||
// 绗竴娆¤闂椂鍙彇褰撳墠姝e湪鎵ц鐨勬垨鑰呮墽琛屽け璐ョ殑
|
||||
query.Where("(isDone=0 OR (isDone=1 AND isOk=0))")
|
||||
}
|
||||
_, err = query.
|
||||
@@ -268,10 +279,10 @@ func (this *NodeTaskDAO) FindDoingNodeTasks(tx *dbs.Tx, role string, nodeId int6
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateNodeTaskDone 修改节点任务的完成状态
|
||||
// UpdateNodeTaskDone 淇敼鑺傜偣浠诲姟鐨勫畬鎴愮姸鎬?
|
||||
func (this *NodeTaskDAO) UpdateNodeTaskDone(tx *dbs.Tx, taskId int64, isOk bool, errorMessage string) error {
|
||||
if isOk {
|
||||
// 特殊任务删除
|
||||
// 鐗规畩浠诲姟鍒犻櫎
|
||||
taskType, err := this.Query(tx).
|
||||
Pk(taskId).
|
||||
Result("type").
|
||||
@@ -286,7 +297,7 @@ func (this *NodeTaskDAO) UpdateNodeTaskDone(tx *dbs.Tx, taskId int64, isOk bool,
|
||||
}
|
||||
}
|
||||
|
||||
// 其他任务标记为完成
|
||||
// 鍏朵粬浠诲姟鏍囪涓哄畬鎴?
|
||||
var query = this.Query(tx).
|
||||
Pk(taskId)
|
||||
if !isOk {
|
||||
@@ -305,7 +316,7 @@ func (this *NodeTaskDAO) UpdateNodeTaskDone(tx *dbs.Tx, taskId int64, isOk bool,
|
||||
return err
|
||||
}
|
||||
|
||||
// FindAllDoingTaskClusterIds 查找正在更新的集群IDs
|
||||
// FindAllDoingTaskClusterIds 鏌ユ壘姝e湪鏇存柊鐨勯泦缇Ds
|
||||
func (this *NodeTaskDAO) FindAllDoingTaskClusterIds(tx *dbs.Tx, role string) ([]int64, error) {
|
||||
ones, _, err := this.Query(tx).
|
||||
Result("DISTINCT(clusterId) AS clusterId").
|
||||
@@ -322,7 +333,7 @@ func (this *NodeTaskDAO) FindAllDoingTaskClusterIds(tx *dbs.Tx, role string) ([]
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// FindAllDoingNodeTasksWithClusterId 查询某个集群下所有的任务
|
||||
// FindAllDoingNodeTasksWithClusterId 鏌ヨ鏌愪釜闆嗙兢涓嬫墍鏈夌殑浠诲姟
|
||||
func (this *NodeTaskDAO) FindAllDoingNodeTasksWithClusterId(tx *dbs.Tx, role string, clusterId int64) (result []*NodeTask, err error) {
|
||||
_, err = this.Query(tx).
|
||||
Attr("role", role).
|
||||
@@ -337,7 +348,7 @@ func (this *NodeTaskDAO) FindAllDoingNodeTasksWithClusterId(tx *dbs.Tx, role str
|
||||
return
|
||||
}
|
||||
|
||||
// FindAllDoingNodeIds 查询有任务的节点IDs
|
||||
// FindAllDoingNodeIds 鏌ヨ鏈変换鍔$殑鑺傜偣IDs
|
||||
func (this *NodeTaskDAO) FindAllDoingNodeIds(tx *dbs.Tx, role string) ([]int64, error) {
|
||||
ones, err := this.Query(tx).
|
||||
Result("DISTINCT(nodeId) AS nodeId").
|
||||
@@ -356,7 +367,7 @@ func (this *NodeTaskDAO) FindAllDoingNodeIds(tx *dbs.Tx, role string) ([]int64,
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ExistsDoingNodeTasks 检查是否有正在执行的任务
|
||||
// ExistsDoingNodeTasks 妫€鏌ユ槸鍚︽湁姝e湪鎵ц鐨勪换鍔?
|
||||
func (this *NodeTaskDAO) ExistsDoingNodeTasks(tx *dbs.Tx, role string, excludeTypes []NodeTaskType) (bool, error) {
|
||||
var query = this.Query(tx).
|
||||
Attr("role", role).
|
||||
@@ -370,7 +381,7 @@ func (this *NodeTaskDAO) ExistsDoingNodeTasks(tx *dbs.Tx, role string, excludeTy
|
||||
return query.Exist()
|
||||
}
|
||||
|
||||
// ExistsErrorNodeTasks 是否有错误的任务
|
||||
// ExistsErrorNodeTasks 鏄惁鏈夐敊璇殑浠诲姟
|
||||
func (this *NodeTaskDAO) ExistsErrorNodeTasks(tx *dbs.Tx, role string, excludeTypes []NodeTaskType) (bool, error) {
|
||||
var query = this.Query(tx).
|
||||
Attr("role", role).
|
||||
@@ -383,7 +394,7 @@ func (this *NodeTaskDAO) ExistsErrorNodeTasks(tx *dbs.Tx, role string, excludeTy
|
||||
return query.Exist()
|
||||
}
|
||||
|
||||
// DeleteNodeTask 删除任务
|
||||
// DeleteNodeTask 鍒犻櫎浠诲姟
|
||||
func (this *NodeTaskDAO) DeleteNodeTask(tx *dbs.Tx, taskId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(taskId).
|
||||
@@ -391,7 +402,7 @@ func (this *NodeTaskDAO) DeleteNodeTask(tx *dbs.Tx, taskId int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// CountDoingNodeTasks 计算正在执行的任务
|
||||
// CountDoingNodeTasks 璁$畻姝e湪鎵ц鐨勪换鍔?
|
||||
func (this *NodeTaskDAO) CountDoingNodeTasks(tx *dbs.Tx, role string) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Attr("isDone", 0).
|
||||
@@ -400,7 +411,7 @@ func (this *NodeTaskDAO) CountDoingNodeTasks(tx *dbs.Tx, role string) (int64, er
|
||||
Count()
|
||||
}
|
||||
|
||||
// FindNotifyingNodeTasks 查找需要通知的任务
|
||||
// FindNotifyingNodeTasks 鏌ユ壘闇€瑕侀€氱煡鐨勪换鍔?
|
||||
func (this *NodeTaskDAO) FindNotifyingNodeTasks(tx *dbs.Tx, role string, size int64) (result []*NodeTask, err error) {
|
||||
_, err = this.Query(tx).
|
||||
Attr("role", role).
|
||||
@@ -413,7 +424,7 @@ func (this *NodeTaskDAO) FindNotifyingNodeTasks(tx *dbs.Tx, role string, size in
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateTasksNotified 设置任务已通知
|
||||
// UpdateTasksNotified 璁剧疆浠诲姟宸查€氱煡
|
||||
func (this *NodeTaskDAO) UpdateTasksNotified(tx *dbs.Tx, taskIds []int64) error {
|
||||
if len(taskIds) == 0 {
|
||||
return nil
|
||||
@@ -430,7 +441,7 @@ func (this *NodeTaskDAO) UpdateTasksNotified(tx *dbs.Tx, taskIds []int64) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// 生成一个版本号
|
||||
// 鐢熸垚涓€涓増鏈彿
|
||||
func (this *NodeTaskDAO) increaseVersion(tx *dbs.Tx) (version int64, err error) {
|
||||
return SharedSysLockerDAO.Increase(tx, "NODE_TASK_VERSION", 0)
|
||||
}
|
||||
|
||||
47
EdgeAPI/internal/db/models/node_task_dao_httpdns.go
Normal file
47
EdgeAPI/internal/db/models/node_task_dao_httpdns.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
// ExtractHTTPDNSClusterTask 分解HTTPDNS节点集群任务
|
||||
func (this *NodeTaskDAO) ExtractHTTPDNSClusterTask(tx *dbs.Tx, clusterId int64, taskType NodeTaskType) error {
|
||||
nodes, err := SharedHTTPDNSNodeDAO.ListEnabledNodes(tx, clusterId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = this.Query(tx).
|
||||
Attr("role", nodeconfigs.NodeRoleHTTPDNS).
|
||||
Attr("clusterId", clusterId).
|
||||
Gt("nodeId", 0).
|
||||
Attr("type", taskType).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
if !node.IsOn {
|
||||
continue
|
||||
}
|
||||
|
||||
err = this.CreateNodeTask(tx, nodeconfigs.NodeRoleHTTPDNS, clusterId, int64(node.Id), 0, 0, taskType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = this.Query(tx).
|
||||
Attr("role", nodeconfigs.NodeRoleHTTPDNS).
|
||||
Attr("clusterId", clusterId).
|
||||
Attr("nodeId", 0).
|
||||
Attr("type", taskType).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user