first commit

This commit is contained in:
2026-02-16 00:13:37 +08:00
commit 74f15c282e
44 changed files with 8708 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
package models
import (
"time"
)
// Website 网站信息
type Website struct {
ID string `json:"id"`
Name string `json:"name"` // 网站名称
Group string `json:"group"` // 所属分组
URLs []URLInfo `json:"urls"` // 网站访问地址列表
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"`
URLStatuses []URLStatus `json:"url_statuses"`
Uptime24h float64 `json:"uptime_24h"` // 24小时可用率
Uptime7d float64 `json:"uptime_7d"` // 7天可用率
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"`
}
// Group 分组
type Group struct {
ID string `json:"id"`
Name string `json:"name"`
}
// DefaultGroups 默认分组
var DefaultGroups = []Group{
{ID: "normal", Name: "普通网站"},
{ID: "admin", Name: "管理员网站"},
}
// CreateWebsiteRequest 创建网站请求
type CreateWebsiteRequest struct {
Name string `json:"name" binding:"required"`
Group string `json:"group" binding:"required"`
URLs []string `json:"urls" binding:"required,min=1"`
}
// UpdateWebsiteRequest 更新网站请求
type UpdateWebsiteRequest struct {
Name string `json:"name"`
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"`
}