mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
用户可以使用管理员设置的公用线路
This commit is contained in:
33
internal/db/models/nameservers/ns_route_category_dao.go
Normal file
33
internal/db/models/nameservers/ns_route_category_dao.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package nameservers
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
const (
|
||||
NSRouteCategoryStateEnabled = 1 // 已启用
|
||||
NSRouteCategoryStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type NSRouteCategoryDAO dbs.DAO
|
||||
|
||||
func NewNSRouteCategoryDAO() *NSRouteCategoryDAO {
|
||||
return dbs.NewDAO(&NSRouteCategoryDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeNSRouteCategories",
|
||||
Model: new(NSRouteCategory),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*NSRouteCategoryDAO)
|
||||
}
|
||||
|
||||
var SharedNSRouteCategoryDAO *NSRouteCategoryDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedNSRouteCategoryDAO = NewNSRouteCategoryDAO()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package nameservers_test
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
)
|
||||
26
internal/db/models/nameservers/ns_route_category_model.go
Normal file
26
internal/db/models/nameservers/ns_route_category_model.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package nameservers
|
||||
|
||||
// NSRouteCategory 线路分类
|
||||
type NSRouteCategory struct {
|
||||
Id uint64 `field:"id"` // ID
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
Name string `field:"name"` // 分类名
|
||||
AdminId uint64 `field:"adminId"` // 管理员ID
|
||||
UserId uint64 `field:"userId"` // 用户ID
|
||||
Order uint32 `field:"order"` // 排序
|
||||
State uint8 `field:"state"` // 状态
|
||||
}
|
||||
|
||||
type NSRouteCategoryOperator struct {
|
||||
Id any // ID
|
||||
IsOn any // 是否启用
|
||||
Name any // 分类名
|
||||
AdminId any // 管理员ID
|
||||
UserId any // 用户ID
|
||||
Order any // 排序
|
||||
State any // 状态
|
||||
}
|
||||
|
||||
func NewNSRouteCategoryOperator() *NSRouteCategoryOperator {
|
||||
return &NSRouteCategoryOperator{}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package nameservers
|
||||
73
internal/db/models/nameservers/ns_route_dao.go
Normal file
73
internal/db/models/nameservers/ns_route_dao.go
Normal file
@@ -0,0 +1,73 @@
|
||||
//go:build !plus
|
||||
|
||||
package nameservers
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
const (
|
||||
NSRouteStateEnabled = 1 // 已启用
|
||||
NSRouteStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type NSRouteDAO dbs.DAO
|
||||
|
||||
func NewNSRouteDAO() *NSRouteDAO {
|
||||
return dbs.NewDAO(&NSRouteDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeNSRoutes",
|
||||
Model: new(NSRoute),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*NSRouteDAO)
|
||||
}
|
||||
|
||||
var SharedNSRouteDAO *NSRouteDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedNSRouteDAO = NewNSRouteDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// EnableNSRoute 启用条目
|
||||
func (this *NSRouteDAO) EnableNSRoute(tx *dbs.Tx, id uint32) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", NSRouteStateEnabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// DisableNSRoute 禁用条目
|
||||
func (this *NSRouteDAO) DisableNSRoute(tx *dbs.Tx, id uint32) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", NSRouteStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// FindEnabledNSRoute 查找启用中的条目
|
||||
func (this *NSRouteDAO) FindEnabledNSRoute(tx *dbs.Tx, id uint32) (*NSRoute, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
State(NSRouteStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*NSRoute), err
|
||||
}
|
||||
|
||||
// FindNSRouteName 根据主键查找名称
|
||||
func (this *NSRouteDAO) FindNSRouteName(tx *dbs.Tx, id uint32) (string, error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
Result("name").
|
||||
FindStringCol("")
|
||||
}
|
||||
6
internal/db/models/nameservers/ns_route_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_route_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package nameservers_test
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
)
|
||||
@@ -7,8 +7,11 @@ type NSRoute struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||
DomainId uint32 `field:"domainId"` // 域名ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
CategoryId uint32 `field:"categoryId"` // 分类ID
|
||||
DomainId uint64 `field:"domainId"` // 域名ID
|
||||
AdminId uint64 `field:"adminId"` // 管理员ID
|
||||
UserId uint64 `field:"userId"` // 用户ID
|
||||
IsPublic bool `field:"isPublic"` // 是否公用(管理员创建的线路)
|
||||
Name string `field:"name"` // 名称
|
||||
Ranges dbs.JSON `field:"ranges"` // 范围
|
||||
Order uint32 `field:"order"` // 排序
|
||||
@@ -18,17 +21,20 @@ type NSRoute struct {
|
||||
}
|
||||
|
||||
type NSRouteOperator struct {
|
||||
Id interface{} // ID
|
||||
IsOn interface{} // 是否启用
|
||||
ClusterId interface{} // 集群ID
|
||||
DomainId interface{} // 域名ID
|
||||
UserId interface{} // 用户ID
|
||||
Name interface{} // 名称
|
||||
Ranges interface{} // 范围
|
||||
Order interface{} // 排序
|
||||
Version interface{} // 版本号
|
||||
Code interface{} // 代号
|
||||
State interface{} // 状态
|
||||
Id any // ID
|
||||
IsOn any // 是否启用
|
||||
ClusterId any // 集群ID
|
||||
CategoryId any // 分类ID
|
||||
DomainId any // 域名ID
|
||||
AdminId any // 管理员ID
|
||||
UserId any // 用户ID
|
||||
IsPublic any // 是否公用(管理员创建的线路)
|
||||
Name any // 名称
|
||||
Ranges any // 范围
|
||||
Order any // 排序
|
||||
Version any // 版本号
|
||||
Code any // 代号
|
||||
State any // 状态
|
||||
}
|
||||
|
||||
func NewNSRouteOperator() *NSRouteOperator {
|
||||
|
||||
@@ -108,7 +108,7 @@ func uploadLogs() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const hashSize = 5
|
||||
const hashSize = 10
|
||||
var hashList = []uint64{}
|
||||
|
||||
Loop:
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user