nezha/model/server.go

39 lines
1.1 KiB
Go
Raw Normal View History

2019-12-08 10:18:29 -05:00
package model
2019-12-10 04:57:57 -05:00
import (
2021-02-28 10:58:04 -05:00
"encoding/json"
2020-12-08 21:27:00 -05:00
"fmt"
"html/template"
2020-10-24 09:29:05 -04:00
"time"
2020-11-10 21:07:45 -05:00
pb "github.com/naiba/nezha/proto"
2019-12-10 04:57:57 -05:00
)
2019-12-08 10:18:29 -05:00
type Server struct {
Common
2021-01-08 08:04:50 -05:00
Name string
Tag string // 分组名
Secret string `gorm:"uniqueIndex" json:"-"`
Note string `json:"-"` // 管理员可见备注
2021-01-29 22:22:59 -05:00
DisplayIndex int // 展示排序,越大越靠前
2021-01-17 09:05:59 -05:00
Host *Host `gorm:"-"`
State *HostState `gorm:"-"`
2021-01-18 00:45:06 -05:00
LastActive time.Time `gorm:"-"`
2019-12-10 04:57:57 -05:00
TaskClose chan error `gorm:"-" json:"-"`
TaskStream pb.NezhaService_RequestTaskServer `gorm:"-" json:"-"`
PrevHourlyTransferIn int64 `gorm:"-" json:"-"` // 上次数据点时的入站使用量
PrevHourlyTransferOut int64 `gorm:"-" json:"-"` // 上次数据点时的出站使用量
2019-12-08 10:18:29 -05:00
}
2020-12-08 21:27:00 -05:00
func (s Server) Marshal() template.JS {
2021-02-28 10:58:04 -05: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-08 21:27:00 -05:00
}