nezha/model/server.go

36 lines
928 B
Go
Raw Normal View History

2019-12-08 23:18:29 +08:00
package model
2019-12-10 17:57:57 +08:00
import (
2021-02-28 23:58:04 +08:00
"encoding/json"
2020-12-09 10:27:00 +08:00
"fmt"
"html/template"
2020-10-24 21:29:05 +08:00
"time"
2020-11-11 10:07:45 +08:00
pb "github.com/naiba/nezha/proto"
2019-12-10 17:57:57 +08:00
)
2019-12-08 23:18:29 +08:00
type Server struct {
Common
2021-01-08 21:04:50 +08:00
Name string
Tag string // 分组名
Secret string `gorm:"uniqueIndex" json:"-"`
Note string `json:"-"` // 管理员可见备注
2021-01-30 11:22:59 +08:00
DisplayIndex int // 展示排序,越大越靠前
2021-01-17 22:05:59 +08:00
Host *Host `gorm:"-"`
State *HostState `gorm:"-"`
2021-01-18 13:45:06 +08:00
LastActive time.Time `gorm:"-"`
2019-12-10 17:57:57 +08:00
TaskClose chan error `gorm:"-" json:"-"`
TaskStream pb.NezhaService_RequestTaskServer `gorm:"-" json:"-"`
2019-12-08 23:18:29 +08:00
}
2020-12-09 10:27:00 +08:00
func (s Server) Marshal() template.JS {
2021-02-28 23:58:04 +08:00
name, _ := json.Marshal(s.Name)
tag, _ := json.Marshal(s.Tag)
note, _ := json.Marshal(s.Note)
secret, _ := json.Marshal(s.Secret)
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s}`,
s.ID, name, secret, s.DisplayIndex, tag, note))
2020-12-09 10:27:00 +08:00
}