阶段性提交

This commit is contained in:
GoEdgeLab
2020-07-24 09:17:48 +08:00
parent 9a751902f4
commit a7879b08d6
53 changed files with 2962 additions and 1696 deletions

View File

@@ -4,6 +4,8 @@ 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"
)
const (
@@ -62,3 +64,48 @@ func (this *NodeDAO) FindNodeName(id uint32) (string, error) {
FindCol("")
return name.(string), err
}
// 创建节点
func (this *NodeDAO) CreateNode(name string, clusterId int) (nodeId int, err error) {
op := NewNodeOperator()
op.Name = name
op.NodeId = rands.HexString(32)
op.Secret = rands.String(32)
op.ClusterId = clusterId
op.State = NodeStateEnabled
_, err = this.Save(op)
if err != nil {
return 0, err
}
return types.Int(op.Id), nil
}
// 修改节点
func (this *NodeDAO) UpdateNode(nodeId int, name string, clusterId int) error {
op := NewNodeOperator()
op.Id = nodeId
op.Name = name
op.ClusterId = clusterId
_, err := this.Save(op)
return err
}
// 计算所有节点数量
func (this *NodeDAO) CountAllEnabledNodes() (int64, error) {
return this.Query().
State(NodeStateEnabled).
Count()
}
// 列出单页节点
func (this *NodeDAO) ListEnabledNodes(offset int64, size int64) (result []*Node, err error) {
_, err = this.Query().
State(NodeStateEnabled).
Offset(int(offset)).
Limit(int(size)).
DescPk().
Slice(&result).
FindAll()
return
}