代码拉取完成,页面将自动刷新
package model
import (
"log"
"time"
"gitee.com/linqwen/momo/base"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
var SrvDb *gorm.DB
func init() {
var err error
SrvDb, err = gorm.Open(sqlite.Open("data/conf.db"), &gorm.Config{})
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
SrvDb.AutoMigrate(&ServiceEntity{})
go healthCheck()
}
func healthCheck() {
time.Sleep(100 * time.Millisecond)
// 使用 where 条件来查找并更新所有符合条件的服务实体
if err := SrvDb.Where("last_seen < ?", time.Now().Add(-120*time.Second)).Update("status", 0).Error; err != nil {
log.Printf("Failed to update service entities: %v", err)
}
}
type ServiceEntity struct {
base.IdTimeStampsModel
Name string `gorm:"column:name" json:"Name" form:"Name" comment:"Name"`
Host string `gorm:"column:host" json:"Host" form:"Host" comment:"Host"`
Port int `gorm:"column:port;default:0" json:"Port" form:"Port" comment:"Port"`
Admin string `gorm:"column:admin" json:"Admin" form:"Admin" comment:"Admin"`
ExePath string `gorm:"column:exe_path" json:"ExePath" form:"ExePath" comment:"ExePath"`
Args string `gorm:"column:args" json:"Args" form:"Args" comment:"Args"`
SystemdName string `gorm:"column:systemd_name" json:"SystemdName" form:"SystemdName" comment:"SystemdName"`
SystemdStatus string `gorm:"column:systemd_status" json:"SystemdStatus" form:"SystemdStatus" comment:"SystemdStatus"`
Status int `gorm:"column:status" json:"Status" form:"Status" comment:"状态"`
// LastSeen base.ISO8601Time `gorm:"column:last_seen" json:"LastSeen" form:"LastSeen" comment:"LastSeen"`
Mode string `gorm:"column:mode" json:"Mode" form:"Mode" comment:"Mode"`
Acl bool `gorm:"column:acl" json:"Acl" form:"Acl" comment:"Acl"`
Acs bool `gorm:"column:acs" json:"Acs" form:"Acs" comment:"Acs"`
Log bool `gorm:"column:log" json:"Log" form:"Log" comment:"Log"`
Cpu int `gorm:"column:cpu" json:"Cpu" form:"Cpu" comment:"Cpu"`
}
func (c ServiceEntity) TableName() string { return "srv_service" }
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。