118 lines
4.2 KiB
Go
118 lines
4.2 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
)
|
||
|
||
// Website 网站信息
|
||
type Website struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"` // 网站名称
|
||
Groups []string `json:"groups"` // 所属分组列表(支持多分组)
|
||
Group string `json:"group,omitempty"` // 已废弃,仅用于旧数据兼容
|
||
URLs []URLInfo `json:"urls"` // 网站访问地址列表
|
||
IPAddresses []string `json:"ip_addresses,omitempty"` // 域名解析的IP地址
|
||
Favicon string `json:"favicon"` // 网站图标URL
|
||
Title string `json:"title"` // 网站标题
|
||
CreatedAt time.Time `json:"created_at"` // 创建时间
|
||
UpdatedAt time.Time `json:"updated_at"` // 更新时间
|
||
}
|
||
|
||
// URLInfo 单个URL的信息
|
||
type URLInfo struct {
|
||
ID string `json:"id"`
|
||
URL string `json:"url"` // 访问地址
|
||
Remark string `json:"remark"` // 备注说明
|
||
}
|
||
|
||
// MonitorRecord 监控记录
|
||
type MonitorRecord struct {
|
||
WebsiteID string `json:"website_id"`
|
||
URLID string `json:"url_id"`
|
||
URL string `json:"url"`
|
||
StatusCode int `json:"status_code"` // HTTP状态码
|
||
Latency int64 `json:"latency"` // 延迟(毫秒)
|
||
IsUp bool `json:"is_up"` // 是否可访问
|
||
Error string `json:"error"` // 错误信息
|
||
CheckedAt time.Time `json:"checked_at"` // 检测时间
|
||
}
|
||
|
||
// WebsiteStatus 网站状态(用于前端展示)
|
||
type WebsiteStatus struct {
|
||
Website Website `json:"website"`
|
||
IsIntranet bool `json:"is_intranet"` // 主 URL 为内网 IP:不解析公网 DNS、不展示解析 IP,用内网图标
|
||
URLStatuses []URLStatus `json:"url_statuses"`
|
||
DailyHistory []DailyStats `json:"daily_history"` // 30天逐日统计
|
||
Uptime24h float64 `json:"uptime_24h"` // 24小时可用率
|
||
Uptime7d float64 `json:"uptime_7d"` // 7天可用率
|
||
Uptime30d float64 `json:"uptime_30d"` // 30天可用率
|
||
LastChecked time.Time `json:"last_checked"` // 最后检测时间
|
||
}
|
||
|
||
// URLStatus 单个URL的状态
|
||
type URLStatus struct {
|
||
URLInfo URLInfo `json:"url_info"`
|
||
CurrentState MonitorRecord `json:"current_state"` // 当前状态
|
||
History24h []MonitorRecord `json:"history_24h"` // 24小时历史
|
||
History7d []HourlyStats `json:"history_7d"` // 7天按小时统计
|
||
Uptime24h float64 `json:"uptime_24h"` // 24小时可用率
|
||
Uptime7d float64 `json:"uptime_7d"` // 7天可用率
|
||
AvgLatency int64 `json:"avg_latency"` // 平均延迟
|
||
}
|
||
|
||
// HourlyStats 每小时统计
|
||
type HourlyStats struct {
|
||
Hour time.Time `json:"hour"`
|
||
TotalCount int `json:"total_count"`
|
||
UpCount int `json:"up_count"`
|
||
AvgLatency int64 `json:"avg_latency"`
|
||
Uptime float64 `json:"uptime"`
|
||
}
|
||
|
||
// DailyStats 每日统计
|
||
type DailyStats struct {
|
||
Date time.Time `json:"date"`
|
||
TotalCount int `json:"total_count"`
|
||
UpCount int `json:"up_count"`
|
||
AvgLatency int64 `json:"avg_latency"`
|
||
Uptime float64 `json:"uptime"`
|
||
}
|
||
|
||
// Group 分组
|
||
type Group struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
}
|
||
|
||
// DefaultGroups 默认分组
|
||
var DefaultGroups = []Group{
|
||
{ID: "normal", Name: "普通网站"},
|
||
{ID: "admin", Name: "管理员网站"},
|
||
}
|
||
|
||
// DefaultIntranetFavicon 直填内网站点的列表图标(静态 SVG,不依赖公网 favicon 抓取)
|
||
const DefaultIntranetFavicon = "https://api.iconify.design/mdi/lan-connect.svg?color=%23059669"
|
||
|
||
// CreateWebsiteRequest 创建网站请求
|
||
type CreateWebsiteRequest struct {
|
||
Name string `json:"name" binding:"required"`
|
||
Groups []string `json:"groups" binding:"required,min=1"`
|
||
Group string `json:"group"`
|
||
URLs []string `json:"urls" binding:"required,min=1"`
|
||
}
|
||
|
||
// UpdateWebsiteRequest 更新网站请求
|
||
type UpdateWebsiteRequest struct {
|
||
Name string `json:"name"`
|
||
Groups []string `json:"groups"`
|
||
Group string `json:"group"`
|
||
URLs []string `json:"urls"`
|
||
}
|
||
|
||
// APIResponse API响应
|
||
type APIResponse struct {
|
||
Code int `json:"code"`
|
||
Message string `json:"message"`
|
||
Data interface{} `json:"data,omitempty"`
|
||
}
|