package models
|
|
import (
|
"sync"
|
)
|
|
const (
|
RUNNING_Currupted = 0
|
RUNNING_Stopped = 1
|
RUNNING_Started = 2
|
)
|
|
type BeeNode struct {
|
Id int `gorm:"column:id;primary_key;unique;not null;autoIncrement" json:"id"` // 节点id
|
Address string `gorm:"column:address;not null;default:''" json:"address"` // 程序目录
|
Dir string `gorm:"column:dir;not null;default:''" json:"dir"` // 程序目录
|
ApiPort uint16 `gorm:"column:api_port" json:"apiPort"` // api port number
|
P2PPort uint16 `gorm:"column:p2p_port" json:"p2pPort"` // p2p port number
|
DebugPort uint16 `gorm:"column:debug_port" json:"debugPort"` // debug port number
|
Status uint8 `gorm:"column:status" json:"status"` // status
|
Del uint8 `gorm:"column:del" json:"del"` // del
|
}
|
|
var (
|
m sync.RWMutex
|
)
|
|
func (BeeNode) TableName() string {
|
return "t_node"
|
}
|
|
func (a *BeeNode) FindAll() ([]BeeNode, error) {
|
var rows []BeeNode
|
|
m.RLock()
|
defer m.RUnlock()
|
if err := db.Table(a.TableName()).Find(&rows).Error; err != nil {
|
return nil, err
|
}
|
|
return rows, nil
|
}
|
|
func (a *BeeNode) Save() error {
|
m.Lock()
|
defer m.Unlock()
|
|
return db.Create(a).Error
|
}
|
|
func (a *BeeNode) Update(status uint8) error {
|
m.Lock()
|
defer m.Unlock()
|
|
return db.Model(a).Update("Status", status).Error
|
}
|