添加代理与节点的注册与端口分配接口功能
This commit is contained in:
@@ -30,10 +30,8 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
_channel.ID = field.NewInt32(tableName, "id")
|
||||
_channel.UserID = field.NewInt32(tableName, "user_id")
|
||||
_channel.ProxyID = field.NewInt32(tableName, "proxy_id")
|
||||
_channel.NodeID = field.NewInt32(tableName, "node_id")
|
||||
_channel.ProxyHost = field.NewString(tableName, "proxy_host")
|
||||
_channel.ProxyPort = field.NewInt32(tableName, "proxy_port")
|
||||
_channel.NodeHost = field.NewString(tableName, "node_host")
|
||||
_channel.Protocol = field.NewInt32(tableName, "protocol")
|
||||
_channel.AuthIP = field.NewBool(tableName, "auth_ip")
|
||||
_channel.AuthPass = field.NewBool(tableName, "auth_pass")
|
||||
@@ -43,6 +41,8 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
_channel.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_channel.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_channel.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_channel.EdgeHost = field.NewString(tableName, "edge_host")
|
||||
_channel.EdgeID = field.NewInt32(tableName, "edge_id")
|
||||
|
||||
_channel.fillFieldMap()
|
||||
|
||||
@@ -56,10 +56,8 @@ type channel struct {
|
||||
ID field.Int32 // 通道ID
|
||||
UserID field.Int32 // 用户ID
|
||||
ProxyID field.Int32 // 代理ID
|
||||
NodeID field.Int32 // 节点ID
|
||||
ProxyHost field.String // 代理地址
|
||||
ProxyPort field.Int32 // 转发端口
|
||||
NodeHost field.String // 节点地址
|
||||
Protocol field.Int32 // 协议类型:1-http,2-https,3-socks5
|
||||
AuthIP field.Bool // IP认证
|
||||
AuthPass field.Bool // 密码认证
|
||||
@@ -69,6 +67,8 @@ type channel struct {
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
EdgeHost field.String // 节点地址
|
||||
EdgeID field.Int32 // 节点ID
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -88,10 +88,8 @@ func (c *channel) updateTableName(table string) *channel {
|
||||
c.ID = field.NewInt32(table, "id")
|
||||
c.UserID = field.NewInt32(table, "user_id")
|
||||
c.ProxyID = field.NewInt32(table, "proxy_id")
|
||||
c.NodeID = field.NewInt32(table, "node_id")
|
||||
c.ProxyHost = field.NewString(table, "proxy_host")
|
||||
c.ProxyPort = field.NewInt32(table, "proxy_port")
|
||||
c.NodeHost = field.NewString(table, "node_host")
|
||||
c.Protocol = field.NewInt32(table, "protocol")
|
||||
c.AuthIP = field.NewBool(table, "auth_ip")
|
||||
c.AuthPass = field.NewBool(table, "auth_pass")
|
||||
@@ -101,6 +99,8 @@ func (c *channel) updateTableName(table string) *channel {
|
||||
c.CreatedAt = field.NewField(table, "created_at")
|
||||
c.UpdatedAt = field.NewField(table, "updated_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
c.EdgeHost = field.NewString(table, "edge_host")
|
||||
c.EdgeID = field.NewInt32(table, "edge_id")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
@@ -121,10 +121,8 @@ func (c *channel) fillFieldMap() {
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["proxy_id"] = c.ProxyID
|
||||
c.fieldMap["node_id"] = c.NodeID
|
||||
c.fieldMap["proxy_host"] = c.ProxyHost
|
||||
c.fieldMap["proxy_port"] = c.ProxyPort
|
||||
c.fieldMap["node_host"] = c.NodeHost
|
||||
c.fieldMap["protocol"] = c.Protocol
|
||||
c.fieldMap["auth_ip"] = c.AuthIP
|
||||
c.fieldMap["auth_pass"] = c.AuthPass
|
||||
@@ -134,6 +132,8 @@ func (c *channel) fillFieldMap() {
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||
c.fieldMap["edge_host"] = c.EdgeHost
|
||||
c.fieldMap["edge_id"] = c.EdgeID
|
||||
}
|
||||
|
||||
func (c channel) clone(db *gorm.DB) channel {
|
||||
|
||||
379
web/queries/edge.gen.go
Normal file
379
web/queries/edge.gen.go
Normal file
@@ -0,0 +1,379 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newEdge(db *gorm.DB, opts ...gen.DOOption) edge {
|
||||
_edge := edge{}
|
||||
|
||||
_edge.edgeDo.UseDB(db, opts...)
|
||||
_edge.edgeDo.UseModel(&models.Edge{})
|
||||
|
||||
tableName := _edge.edgeDo.TableName()
|
||||
_edge.ALL = field.NewAsterisk(tableName)
|
||||
_edge.ID = field.NewInt32(tableName, "id")
|
||||
_edge.ProxyID = field.NewInt32(tableName, "proxy_id")
|
||||
_edge.Type = field.NewInt32(tableName, "type")
|
||||
_edge.Version = field.NewInt32(tableName, "version")
|
||||
_edge.Name = field.NewString(tableName, "name")
|
||||
_edge.Host = field.NewString(tableName, "host")
|
||||
_edge.Isp = field.NewInt32(tableName, "isp")
|
||||
_edge.Prov = field.NewString(tableName, "prov")
|
||||
_edge.City = field.NewString(tableName, "city")
|
||||
_edge.ProxyPort = field.NewInt32(tableName, "proxy_port")
|
||||
_edge.Status = field.NewInt32(tableName, "status")
|
||||
_edge.Rtt = field.NewInt32(tableName, "rtt")
|
||||
_edge.Loss = field.NewInt32(tableName, "loss")
|
||||
_edge.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_edge.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_edge.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_edge.fillFieldMap()
|
||||
|
||||
return _edge
|
||||
}
|
||||
|
||||
type edge struct {
|
||||
edgeDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // 节点ID
|
||||
ProxyID field.Int32 // 代理ID
|
||||
Type field.Int32 // 节点类型:1-自建
|
||||
Version field.Int32 // 节点版本
|
||||
Name field.String // 节点名称
|
||||
Host field.String // 节点地址
|
||||
Isp field.Int32 // 运营商:0-未知,1-电信,2-联通,3-移动
|
||||
Prov field.String // 省份
|
||||
City field.String // 城市
|
||||
ProxyPort field.Int32 // 代理端口
|
||||
Status field.Int32 // 节点状态:0-离线,1-正常
|
||||
Rtt field.Int32 // 最近平均延迟
|
||||
Loss field.Int32 // 最近丢包率
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (e edge) Table(newTableName string) *edge {
|
||||
e.edgeDo.UseTable(newTableName)
|
||||
return e.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (e edge) As(alias string) *edge {
|
||||
e.edgeDo.DO = *(e.edgeDo.As(alias).(*gen.DO))
|
||||
return e.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (e *edge) updateTableName(table string) *edge {
|
||||
e.ALL = field.NewAsterisk(table)
|
||||
e.ID = field.NewInt32(table, "id")
|
||||
e.ProxyID = field.NewInt32(table, "proxy_id")
|
||||
e.Type = field.NewInt32(table, "type")
|
||||
e.Version = field.NewInt32(table, "version")
|
||||
e.Name = field.NewString(table, "name")
|
||||
e.Host = field.NewString(table, "host")
|
||||
e.Isp = field.NewInt32(table, "isp")
|
||||
e.Prov = field.NewString(table, "prov")
|
||||
e.City = field.NewString(table, "city")
|
||||
e.ProxyPort = field.NewInt32(table, "proxy_port")
|
||||
e.Status = field.NewInt32(table, "status")
|
||||
e.Rtt = field.NewInt32(table, "rtt")
|
||||
e.Loss = field.NewInt32(table, "loss")
|
||||
e.CreatedAt = field.NewField(table, "created_at")
|
||||
e.UpdatedAt = field.NewField(table, "updated_at")
|
||||
e.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
e.fillFieldMap()
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *edge) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := e.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (e *edge) fillFieldMap() {
|
||||
e.fieldMap = make(map[string]field.Expr, 16)
|
||||
e.fieldMap["id"] = e.ID
|
||||
e.fieldMap["proxy_id"] = e.ProxyID
|
||||
e.fieldMap["type"] = e.Type
|
||||
e.fieldMap["version"] = e.Version
|
||||
e.fieldMap["name"] = e.Name
|
||||
e.fieldMap["host"] = e.Host
|
||||
e.fieldMap["isp"] = e.Isp
|
||||
e.fieldMap["prov"] = e.Prov
|
||||
e.fieldMap["city"] = e.City
|
||||
e.fieldMap["proxy_port"] = e.ProxyPort
|
||||
e.fieldMap["status"] = e.Status
|
||||
e.fieldMap["rtt"] = e.Rtt
|
||||
e.fieldMap["loss"] = e.Loss
|
||||
e.fieldMap["created_at"] = e.CreatedAt
|
||||
e.fieldMap["updated_at"] = e.UpdatedAt
|
||||
e.fieldMap["deleted_at"] = e.DeletedAt
|
||||
}
|
||||
|
||||
func (e edge) clone(db *gorm.DB) edge {
|
||||
e.edgeDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e edge) replaceDB(db *gorm.DB) edge {
|
||||
e.edgeDo.ReplaceDB(db)
|
||||
return e
|
||||
}
|
||||
|
||||
type edgeDo struct{ gen.DO }
|
||||
|
||||
func (e edgeDo) Debug() *edgeDo {
|
||||
return e.withDO(e.DO.Debug())
|
||||
}
|
||||
|
||||
func (e edgeDo) WithContext(ctx context.Context) *edgeDo {
|
||||
return e.withDO(e.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (e edgeDo) ReadDB() *edgeDo {
|
||||
return e.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (e edgeDo) WriteDB() *edgeDo {
|
||||
return e.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (e edgeDo) Session(config *gorm.Session) *edgeDo {
|
||||
return e.withDO(e.DO.Session(config))
|
||||
}
|
||||
|
||||
func (e edgeDo) Clauses(conds ...clause.Expression) *edgeDo {
|
||||
return e.withDO(e.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Returning(value interface{}, columns ...string) *edgeDo {
|
||||
return e.withDO(e.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Not(conds ...gen.Condition) *edgeDo {
|
||||
return e.withDO(e.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Or(conds ...gen.Condition) *edgeDo {
|
||||
return e.withDO(e.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Select(conds ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Where(conds ...gen.Condition) *edgeDo {
|
||||
return e.withDO(e.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Order(conds ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Distinct(cols ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Omit(cols ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Join(table schema.Tabler, on ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (e edgeDo) LeftJoin(table schema.Tabler, on ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (e edgeDo) RightJoin(table schema.Tabler, on ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Group(cols ...field.Expr) *edgeDo {
|
||||
return e.withDO(e.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Having(conds ...gen.Condition) *edgeDo {
|
||||
return e.withDO(e.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Limit(limit int) *edgeDo {
|
||||
return e.withDO(e.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (e edgeDo) Offset(offset int) *edgeDo {
|
||||
return e.withDO(e.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (e edgeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *edgeDo {
|
||||
return e.withDO(e.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Unscoped() *edgeDo {
|
||||
return e.withDO(e.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (e edgeDo) Create(values ...*models.Edge) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return e.DO.Create(values)
|
||||
}
|
||||
|
||||
func (e edgeDo) CreateInBatches(values []*models.Edge, batchSize int) error {
|
||||
return e.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (e edgeDo) Save(values ...*models.Edge) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return e.DO.Save(values)
|
||||
}
|
||||
|
||||
func (e edgeDo) First() (*models.Edge, error) {
|
||||
if result, err := e.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Edge), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e edgeDo) Take() (*models.Edge, error) {
|
||||
if result, err := e.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Edge), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e edgeDo) Last() (*models.Edge, error) {
|
||||
if result, err := e.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Edge), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e edgeDo) Find() ([]*models.Edge, error) {
|
||||
result, err := e.DO.Find()
|
||||
return result.([]*models.Edge), err
|
||||
}
|
||||
|
||||
func (e edgeDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Edge, err error) {
|
||||
buf := make([]*models.Edge, 0, batchSize)
|
||||
err = e.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (e edgeDo) FindInBatches(result *[]*models.Edge, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return e.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (e edgeDo) Attrs(attrs ...field.AssignExpr) *edgeDo {
|
||||
return e.withDO(e.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Assign(attrs ...field.AssignExpr) *edgeDo {
|
||||
return e.withDO(e.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (e edgeDo) Joins(fields ...field.RelationField) *edgeDo {
|
||||
for _, _f := range fields {
|
||||
e = *e.withDO(e.DO.Joins(_f))
|
||||
}
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e edgeDo) Preload(fields ...field.RelationField) *edgeDo {
|
||||
for _, _f := range fields {
|
||||
e = *e.withDO(e.DO.Preload(_f))
|
||||
}
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e edgeDo) FirstOrInit() (*models.Edge, error) {
|
||||
if result, err := e.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Edge), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e edgeDo) FirstOrCreate() (*models.Edge, error) {
|
||||
if result, err := e.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Edge), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e edgeDo) FindByPage(offset int, limit int) (result []*models.Edge, count int64, err error) {
|
||||
result, err = e.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = e.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (e edgeDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = e.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = e.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (e edgeDo) Scan(result interface{}) (err error) {
|
||||
return e.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (e edgeDo) Delete(models ...*models.Edge) (result gen.ResultInfo, err error) {
|
||||
return e.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (e *edgeDo) withDO(do gen.Dao) *edgeDo {
|
||||
e.DO = *do.(*gen.DO)
|
||||
return e
|
||||
}
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
Client *client
|
||||
ClientPermissionLink *clientPermissionLink
|
||||
Coupon *coupon
|
||||
Edge *edge
|
||||
LogsRequest *logsRequest
|
||||
Node *node
|
||||
Permission *permission
|
||||
Product *product
|
||||
Proxy *proxy
|
||||
@@ -58,8 +58,8 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
Client = &Q.Client
|
||||
ClientPermissionLink = &Q.ClientPermissionLink
|
||||
Coupon = &Q.Coupon
|
||||
Edge = &Q.Edge
|
||||
LogsRequest = &Q.LogsRequest
|
||||
Node = &Q.Node
|
||||
Permission = &Q.Permission
|
||||
Product = &Q.Product
|
||||
Proxy = &Q.Proxy
|
||||
@@ -90,8 +90,8 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
Client: newClient(db, opts...),
|
||||
ClientPermissionLink: newClientPermissionLink(db, opts...),
|
||||
Coupon: newCoupon(db, opts...),
|
||||
Edge: newEdge(db, opts...),
|
||||
LogsRequest: newLogsRequest(db, opts...),
|
||||
Node: newNode(db, opts...),
|
||||
Permission: newPermission(db, opts...),
|
||||
Product: newProduct(db, opts...),
|
||||
Proxy: newProxy(db, opts...),
|
||||
@@ -123,8 +123,8 @@ type Query struct {
|
||||
Client client
|
||||
ClientPermissionLink clientPermissionLink
|
||||
Coupon coupon
|
||||
Edge edge
|
||||
LogsRequest logsRequest
|
||||
Node node
|
||||
Permission permission
|
||||
Product product
|
||||
Proxy proxy
|
||||
@@ -157,8 +157,8 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
Client: q.Client.clone(db),
|
||||
ClientPermissionLink: q.ClientPermissionLink.clone(db),
|
||||
Coupon: q.Coupon.clone(db),
|
||||
Edge: q.Edge.clone(db),
|
||||
LogsRequest: q.LogsRequest.clone(db),
|
||||
Node: q.Node.clone(db),
|
||||
Permission: q.Permission.clone(db),
|
||||
Product: q.Product.clone(db),
|
||||
Proxy: q.Proxy.clone(db),
|
||||
@@ -198,8 +198,8 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
Client: q.Client.replaceDB(db),
|
||||
ClientPermissionLink: q.ClientPermissionLink.replaceDB(db),
|
||||
Coupon: q.Coupon.replaceDB(db),
|
||||
Edge: q.Edge.replaceDB(db),
|
||||
LogsRequest: q.LogsRequest.replaceDB(db),
|
||||
Node: q.Node.replaceDB(db),
|
||||
Permission: q.Permission.replaceDB(db),
|
||||
Product: q.Product.replaceDB(db),
|
||||
Proxy: q.Proxy.replaceDB(db),
|
||||
@@ -229,8 +229,8 @@ type queryCtx struct {
|
||||
Client *clientDo
|
||||
ClientPermissionLink *clientPermissionLinkDo
|
||||
Coupon *couponDo
|
||||
Edge *edgeDo
|
||||
LogsRequest *logsRequestDo
|
||||
Node *nodeDo
|
||||
Permission *permissionDo
|
||||
Product *productDo
|
||||
Proxy *proxyDo
|
||||
@@ -260,8 +260,8 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
Client: q.Client.WithContext(ctx),
|
||||
ClientPermissionLink: q.ClientPermissionLink.WithContext(ctx),
|
||||
Coupon: q.Coupon.WithContext(ctx),
|
||||
Edge: q.Edge.WithContext(ctx),
|
||||
LogsRequest: q.LogsRequest.WithContext(ctx),
|
||||
Node: q.Node.WithContext(ctx),
|
||||
Permission: q.Permission.WithContext(ctx),
|
||||
Product: q.Product.WithContext(ctx),
|
||||
Proxy: q.Proxy.WithContext(ctx),
|
||||
|
||||
@@ -1,375 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newNode(db *gorm.DB, opts ...gen.DOOption) node {
|
||||
_node := node{}
|
||||
|
||||
_node.nodeDo.UseDB(db, opts...)
|
||||
_node.nodeDo.UseModel(&models.Node{})
|
||||
|
||||
tableName := _node.nodeDo.TableName()
|
||||
_node.ALL = field.NewAsterisk(tableName)
|
||||
_node.ID = field.NewInt32(tableName, "id")
|
||||
_node.ProxyID = field.NewInt32(tableName, "proxy_id")
|
||||
_node.Version = field.NewInt32(tableName, "version")
|
||||
_node.Name = field.NewString(tableName, "name")
|
||||
_node.Host = field.NewString(tableName, "host")
|
||||
_node.Isp = field.NewInt32(tableName, "isp")
|
||||
_node.Prov = field.NewString(tableName, "prov")
|
||||
_node.City = field.NewString(tableName, "city")
|
||||
_node.ProxyPort = field.NewInt32(tableName, "proxy_port")
|
||||
_node.Status = field.NewInt32(tableName, "status")
|
||||
_node.Rtt = field.NewInt32(tableName, "rtt")
|
||||
_node.Loss = field.NewInt32(tableName, "loss")
|
||||
_node.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_node.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_node.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_node.fillFieldMap()
|
||||
|
||||
return _node
|
||||
}
|
||||
|
||||
type node struct {
|
||||
nodeDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // 节点ID
|
||||
ProxyID field.Int32 // 代理ID
|
||||
Version field.Int32 // 节点版本
|
||||
Name field.String // 节点名称
|
||||
Host field.String // 节点地址
|
||||
Isp field.Int32 // 运营商:0-未知,1-电信,2-联通,3-移动
|
||||
Prov field.String // 省份
|
||||
City field.String // 城市
|
||||
ProxyPort field.Int32 // 代理端口
|
||||
Status field.Int32 // 节点状态:0-离线,1-正常
|
||||
Rtt field.Int32 // 延迟
|
||||
Loss field.Int32 // 丢包率
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (n node) Table(newTableName string) *node {
|
||||
n.nodeDo.UseTable(newTableName)
|
||||
return n.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (n node) As(alias string) *node {
|
||||
n.nodeDo.DO = *(n.nodeDo.As(alias).(*gen.DO))
|
||||
return n.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (n *node) updateTableName(table string) *node {
|
||||
n.ALL = field.NewAsterisk(table)
|
||||
n.ID = field.NewInt32(table, "id")
|
||||
n.ProxyID = field.NewInt32(table, "proxy_id")
|
||||
n.Version = field.NewInt32(table, "version")
|
||||
n.Name = field.NewString(table, "name")
|
||||
n.Host = field.NewString(table, "host")
|
||||
n.Isp = field.NewInt32(table, "isp")
|
||||
n.Prov = field.NewString(table, "prov")
|
||||
n.City = field.NewString(table, "city")
|
||||
n.ProxyPort = field.NewInt32(table, "proxy_port")
|
||||
n.Status = field.NewInt32(table, "status")
|
||||
n.Rtt = field.NewInt32(table, "rtt")
|
||||
n.Loss = field.NewInt32(table, "loss")
|
||||
n.CreatedAt = field.NewField(table, "created_at")
|
||||
n.UpdatedAt = field.NewField(table, "updated_at")
|
||||
n.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
n.fillFieldMap()
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *node) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := n.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (n *node) fillFieldMap() {
|
||||
n.fieldMap = make(map[string]field.Expr, 15)
|
||||
n.fieldMap["id"] = n.ID
|
||||
n.fieldMap["proxy_id"] = n.ProxyID
|
||||
n.fieldMap["version"] = n.Version
|
||||
n.fieldMap["name"] = n.Name
|
||||
n.fieldMap["host"] = n.Host
|
||||
n.fieldMap["isp"] = n.Isp
|
||||
n.fieldMap["prov"] = n.Prov
|
||||
n.fieldMap["city"] = n.City
|
||||
n.fieldMap["proxy_port"] = n.ProxyPort
|
||||
n.fieldMap["status"] = n.Status
|
||||
n.fieldMap["rtt"] = n.Rtt
|
||||
n.fieldMap["loss"] = n.Loss
|
||||
n.fieldMap["created_at"] = n.CreatedAt
|
||||
n.fieldMap["updated_at"] = n.UpdatedAt
|
||||
n.fieldMap["deleted_at"] = n.DeletedAt
|
||||
}
|
||||
|
||||
func (n node) clone(db *gorm.DB) node {
|
||||
n.nodeDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return n
|
||||
}
|
||||
|
||||
func (n node) replaceDB(db *gorm.DB) node {
|
||||
n.nodeDo.ReplaceDB(db)
|
||||
return n
|
||||
}
|
||||
|
||||
type nodeDo struct{ gen.DO }
|
||||
|
||||
func (n nodeDo) Debug() *nodeDo {
|
||||
return n.withDO(n.DO.Debug())
|
||||
}
|
||||
|
||||
func (n nodeDo) WithContext(ctx context.Context) *nodeDo {
|
||||
return n.withDO(n.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (n nodeDo) ReadDB() *nodeDo {
|
||||
return n.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (n nodeDo) WriteDB() *nodeDo {
|
||||
return n.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (n nodeDo) Session(config *gorm.Session) *nodeDo {
|
||||
return n.withDO(n.DO.Session(config))
|
||||
}
|
||||
|
||||
func (n nodeDo) Clauses(conds ...clause.Expression) *nodeDo {
|
||||
return n.withDO(n.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Returning(value interface{}, columns ...string) *nodeDo {
|
||||
return n.withDO(n.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Not(conds ...gen.Condition) *nodeDo {
|
||||
return n.withDO(n.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Or(conds ...gen.Condition) *nodeDo {
|
||||
return n.withDO(n.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Select(conds ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Where(conds ...gen.Condition) *nodeDo {
|
||||
return n.withDO(n.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Order(conds ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Distinct(cols ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Omit(cols ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Join(table schema.Tabler, on ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (n nodeDo) LeftJoin(table schema.Tabler, on ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (n nodeDo) RightJoin(table schema.Tabler, on ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Group(cols ...field.Expr) *nodeDo {
|
||||
return n.withDO(n.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Having(conds ...gen.Condition) *nodeDo {
|
||||
return n.withDO(n.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Limit(limit int) *nodeDo {
|
||||
return n.withDO(n.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (n nodeDo) Offset(offset int) *nodeDo {
|
||||
return n.withDO(n.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (n nodeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *nodeDo {
|
||||
return n.withDO(n.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Unscoped() *nodeDo {
|
||||
return n.withDO(n.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (n nodeDo) Create(values ...*models.Node) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return n.DO.Create(values)
|
||||
}
|
||||
|
||||
func (n nodeDo) CreateInBatches(values []*models.Node, batchSize int) error {
|
||||
return n.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (n nodeDo) Save(values ...*models.Node) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return n.DO.Save(values)
|
||||
}
|
||||
|
||||
func (n nodeDo) First() (*models.Node, error) {
|
||||
if result, err := n.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Node), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (n nodeDo) Take() (*models.Node, error) {
|
||||
if result, err := n.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Node), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (n nodeDo) Last() (*models.Node, error) {
|
||||
if result, err := n.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Node), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (n nodeDo) Find() ([]*models.Node, error) {
|
||||
result, err := n.DO.Find()
|
||||
return result.([]*models.Node), err
|
||||
}
|
||||
|
||||
func (n nodeDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Node, err error) {
|
||||
buf := make([]*models.Node, 0, batchSize)
|
||||
err = n.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (n nodeDo) FindInBatches(result *[]*models.Node, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return n.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (n nodeDo) Attrs(attrs ...field.AssignExpr) *nodeDo {
|
||||
return n.withDO(n.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Assign(attrs ...field.AssignExpr) *nodeDo {
|
||||
return n.withDO(n.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (n nodeDo) Joins(fields ...field.RelationField) *nodeDo {
|
||||
for _, _f := range fields {
|
||||
n = *n.withDO(n.DO.Joins(_f))
|
||||
}
|
||||
return &n
|
||||
}
|
||||
|
||||
func (n nodeDo) Preload(fields ...field.RelationField) *nodeDo {
|
||||
for _, _f := range fields {
|
||||
n = *n.withDO(n.DO.Preload(_f))
|
||||
}
|
||||
return &n
|
||||
}
|
||||
|
||||
func (n nodeDo) FirstOrInit() (*models.Node, error) {
|
||||
if result, err := n.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Node), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (n nodeDo) FirstOrCreate() (*models.Node, error) {
|
||||
if result, err := n.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.Node), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (n nodeDo) FindByPage(offset int, limit int) (result []*models.Node, count int64, err error) {
|
||||
result, err = n.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = n.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (n nodeDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = n.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = n.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (n nodeDo) Scan(result interface{}) (err error) {
|
||||
return n.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (n nodeDo) Delete(models ...*models.Node) (result gen.ResultInfo, err error) {
|
||||
return n.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (n *nodeDo) withDO(do gen.Dao) *nodeDo {
|
||||
n.DO = *do.(*gen.DO)
|
||||
return n
|
||||
}
|
||||
@@ -36,6 +36,11 @@ func newProxy(db *gorm.DB, opts ...gen.DOOption) proxy {
|
||||
_proxy.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_proxy.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_proxy.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_proxy.Edges = proxyHasManyEdges{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Edges", "models.Edge"),
|
||||
}
|
||||
|
||||
_proxy.fillFieldMap()
|
||||
|
||||
@@ -55,6 +60,7 @@ type proxy struct {
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
Edges proxyHasManyEdges
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -96,7 +102,7 @@ func (p *proxy) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (p *proxy) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 9)
|
||||
p.fieldMap = make(map[string]field.Expr, 10)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["version"] = p.Version
|
||||
p.fieldMap["name"] = p.Name
|
||||
@@ -106,6 +112,7 @@ func (p *proxy) fillFieldMap() {
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
p.fieldMap["deleted_at"] = p.DeletedAt
|
||||
|
||||
}
|
||||
|
||||
func (p proxy) clone(db *gorm.DB) proxy {
|
||||
@@ -118,6 +125,77 @@ func (p proxy) replaceDB(db *gorm.DB) proxy {
|
||||
return p
|
||||
}
|
||||
|
||||
type proxyHasManyEdges struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdges) Where(conds ...field.Expr) *proxyHasManyEdges {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdges) WithContext(ctx context.Context) *proxyHasManyEdges {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdges) Session(session *gorm.Session) *proxyHasManyEdges {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdges) Model(m *models.Proxy) *proxyHasManyEdgesTx {
|
||||
return &proxyHasManyEdgesTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type proxyHasManyEdgesTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a proxyHasManyEdgesTx) Find() (result []*models.Edge, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdgesTx) Append(values ...*models.Edge) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdgesTx) Replace(values ...*models.Edge) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdgesTx) Delete(values ...*models.Edge) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdgesTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a proxyHasManyEdgesTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type proxyDo struct{ gen.DO }
|
||||
|
||||
func (p proxyDo) Debug() *proxyDo {
|
||||
|
||||
Reference in New Issue
Block a user