init: EZOps AIOps 智能运维平台
- 前端: React 18 + TypeScript + Vite + Tailwind CSS + shadcn/ui - 后端: Go + Gin + GORM + JWT (golang-jwt/jwt/v5) - 功能: 服务器管理、K8s集群、监控告警、CI/CD、自动化运维、审批流程、审计日志 - 文档: 设计文档(ROADMAP/PDD/架构/模块)
This commit is contained in:
commit
7d6674bddd
156 files changed
+45704
No files matched your search
@@ -0,0 +1,137 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// AlertRule 告警规则模型
|
||||
type AlertRule struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // metric, log, event
|
||||
Source string `gorm:"size:64;not null" json:"source"` // prometheus, zabbix, custom
|
||||
Expression string `gorm:"type:text;not null" json:"expression"`
|
||||
Severity string `gorm:"size:32;default:warning" json:"severity"` // info, warning, critical
|
||||
Duration int `json:"duration"` // 持续时间(秒)
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
Labels string `gorm:"type:text" json:"labels"` // JSON
|
||||
Annotations string `gorm:"type:text" json:"annotations"` // JSON
|
||||
NotifyChannels string `gorm:"type:text" json:"notify_channels"` // JSON
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (AlertRule) TableName() string {
|
||||
return "alert_rules"
|
||||
}
|
||||
|
||||
// AlertEvent 告警事件模型
|
||||
type AlertEvent struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
RuleID uint `json:"rule_id"`
|
||||
RuleName string `gorm:"size:128" json:"rule_name"`
|
||||
Severity string `gorm:"size:32" json:"severity"`
|
||||
Status string `gorm:"size:32;default:firing" json:"status"` // firing, resolved
|
||||
Target string `gorm:"size:255" json:"target"`
|
||||
Message string `gorm:"type:text" json:"message"`
|
||||
Value float64 `json:"value"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
ResolvedAt *time.Time `json:"resolved_at"`
|
||||
Acknowledged bool `json:"acknowledged"`
|
||||
AcknowledgedBy *uint `json:"acknowledged_by"`
|
||||
AcknowledgedAt *time.Time `json:"acknowledged_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Rule *AlertRule `json:"rule,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (AlertEvent) TableName() string {
|
||||
return "alert_events"
|
||||
}
|
||||
|
||||
// NotifyChannel 通知渠道模型
|
||||
type NotifyChannel struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // email, sms, webhook, dingtalk, wechat
|
||||
Config string `gorm:"type:text" json:"config"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
TestStatus string `gorm:"size:32" json:"test_status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (NotifyChannel) TableName() string {
|
||||
return "notify_channels"
|
||||
}
|
||||
|
||||
// MetricData 监控指标数据
|
||||
type MetricData struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ServerID *uint `json:"server_id"`
|
||||
ClusterID *uint `json:"cluster_id"`
|
||||
Name string `gorm:"size:64" json:"name"`
|
||||
Value float64 `json:"value"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (MetricData) TableName() string {
|
||||
return "metric_data"
|
||||
}
|
||||
|
||||
// CreateAlertRuleRequest 创建告警规则请求
|
||||
type CreateAlertRuleRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type" binding:"required,oneof=metric log event"`
|
||||
Source string `json:"source" binding:"required"`
|
||||
Expression string `json:"expression" binding:"required"`
|
||||
Severity string `json:"severity" binding:"omitempty,oneof=info warning critical"`
|
||||
Duration int `json:"duration"`
|
||||
Labels string `json:"labels"`
|
||||
Annotations string `json:"annotations"`
|
||||
NotifyChannels []string `json:"notify_channels"`
|
||||
}
|
||||
|
||||
// UpdateAlertRuleRequest 更新告警规则请求
|
||||
type UpdateAlertRuleRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Expression string `json:"expression"`
|
||||
Severity string `json:"severity" binding:"omitempty,oneof=info warning critical"`
|
||||
Duration int `json:"duration"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
Labels string `json:"labels"`
|
||||
Annotations string `json:"annotations"`
|
||||
NotifyChannels []string `json:"notify_channels"`
|
||||
}
|
||||
|
||||
// AlertStats 告警统计
|
||||
type AlertStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Firing int64 `json:"firing"`
|
||||
Resolved int64 `json:"resolved"`
|
||||
Critical int64 `json:"critical"`
|
||||
Warning int64 `json:"warning"`
|
||||
Info int64 `json:"info"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
}
|
||||
|
||||
// AcknowledgeAlertRequest 确认告警请求
|
||||
type AcknowledgeAlertRequest struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ApprovalTemplate 审批模板模型
|
||||
type ApprovalTemplate struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // release, server, permission
|
||||
FormSchema string `gorm:"type:text" json:"form_schema"` // JSON
|
||||
FlowConfig string `gorm:"type:text" json:"flow_config"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (ApprovalTemplate) TableName() string {
|
||||
return "approval_templates"
|
||||
}
|
||||
|
||||
// ApprovalProcess 审批流程模型
|
||||
type ApprovalProcess struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TemplateID uint `json:"template_id"`
|
||||
Title string `gorm:"size:255;not null" json:"title"`
|
||||
Applicant uint `json:"applicant"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
||||
FormData string `gorm:"type:text" json:"form_data"` // JSON
|
||||
CurrentStep int `gorm:"default:0" json:"current_step"`
|
||||
TotalSteps int `json:"total_steps"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
RejectedAt *time.Time `json:"rejected_at"`
|
||||
RejectReason string `gorm:"size:500" json:"reject_reason"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Template *ApprovalTemplate `json:"template,omitempty"`
|
||||
ApplicantUser *User `json:"applicant_user,omitempty"`
|
||||
Steps []ApprovalStep `json:"steps,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (ApprovalProcess) TableName() string {
|
||||
return "approval_processes"
|
||||
}
|
||||
|
||||
// ApprovalStep 审批步骤模型
|
||||
type ApprovalStep struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ProcessID uint `json:"process_id"`
|
||||
Step int `json:"step"`
|
||||
Approver uint `json:"approver"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
||||
Comment string `gorm:"size:500" json:"comment"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
ApproverUser *User `json:"approver_user,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (ApprovalStep) TableName() string {
|
||||
return "approval_steps"
|
||||
}
|
||||
|
||||
// CreateApprovalTemplateRequest 创建审批模板请求
|
||||
type CreateApprovalTemplateRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type" binding:"required,oneof=release server permission"`
|
||||
FormSchema string `json:"form_schema"`
|
||||
FlowConfig string `json:"flow_config"`
|
||||
}
|
||||
|
||||
// CreateApprovalProcessRequest 创建审批流程请求
|
||||
type CreateApprovalProcessRequest struct {
|
||||
TemplateID uint `json:"template_id" binding:"required"`
|
||||
Title string `json:"title" binding:"required"`
|
||||
FormData string `json:"form_data"`
|
||||
}
|
||||
|
||||
// ApproveRequest 审批请求
|
||||
type ApproveRequest struct {
|
||||
Status string `json:"status" binding:"required,oneof=approved rejected"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
// ApprovalStats 审批统计
|
||||
type ApprovalStats struct {
|
||||
Pending int64 `json:"pending"`
|
||||
Approved int64 `json:"approved"`
|
||||
Rejected int64 `json:"rejected"`
|
||||
Total int64 `json:"total"`
|
||||
MyPending int64 `json:"my_pending"`
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// AuditLog 审计日志模型
|
||||
type AuditLog struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
UserID *uint `json:"user_id"`
|
||||
Username string `gorm:"size:64" json:"username"`
|
||||
IP string `gorm:"size:64" json:"ip"`
|
||||
UserAgent string `gorm:"size:500" json:"user_agent"`
|
||||
Module string `gorm:"size:64" json:"module"`
|
||||
Action string `gorm:"size:64" json:"action"`
|
||||
Resource string `gorm:"size:128" json:"resource"`
|
||||
ResourceID string `gorm:"size:64" json:"resource_id"`
|
||||
Request string `gorm:"type:text" json:"request"`
|
||||
Response string `gorm:"type:text" json:"response"`
|
||||
Status int `json:"status"`
|
||||
Duration int `json:"duration"` // ms
|
||||
Error string `gorm:"type:text" json:"error"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (AuditLog) TableName() string {
|
||||
return "audit_logs"
|
||||
}
|
||||
|
||||
// AuditLogQuery 审计日志查询
|
||||
type AuditLogQuery struct {
|
||||
UserID *uint `form:"user_id"`
|
||||
Username string `form:"username"`
|
||||
Module string `form:"module"`
|
||||
Action string `form:"action"`
|
||||
StartTime string `form:"start_time"`
|
||||
EndTime string `form:"end_time"`
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
}
|
||||
|
||||
// AuditLogListResponse 审计日志列表响应
|
||||
type AuditLogListResponse struct {
|
||||
List []AuditLog `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// AuditStats 审计统计
|
||||
type AuditStats struct {
|
||||
TodayCount int64 `json:"today_count"`
|
||||
WeekCount int64 `json:"week_count"`
|
||||
MonthCount int64 `json:"month_count"`
|
||||
TopModules []ModuleStat `json:"top_modules"`
|
||||
TopUsers []UserStat `json:"top_users"`
|
||||
}
|
||||
|
||||
// ModuleStat 模块统计
|
||||
type ModuleStat struct {
|
||||
Module string `json:"module"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
// UserStat 用户统计
|
||||
type UserStat struct {
|
||||
Username string `json:"username"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CronJob 定时任务模型
|
||||
type CronJob struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
CronExpr string `gorm:"size:64;not null" json:"cron_expr"`
|
||||
Type string `gorm:"size:32;not null" json:"type"` // script, command, playbook
|
||||
Content string `gorm:"type:text" json:"content"`
|
||||
ScriptID *uint `json:"script_id"`
|
||||
TargetType string `gorm:"size:32;default:server" json:"target_type"` // server, group, tag
|
||||
Targets string `gorm:"type:text" json:"targets"` // JSON
|
||||
Timeout int `gorm:"default:300" json:"timeout"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
LastRunAt *time.Time `json:"last_run_at"`
|
||||
LastStatus string `gorm:"size:32" json:"last_status"`
|
||||
RunCount int `gorm:"default:0" json:"run_count"`
|
||||
SuccessCount int `gorm:"default:0" json:"success_count"`
|
||||
FailCount int `gorm:"default:0" json:"fail_count"`
|
||||
NotifyOn string `gorm:"size:32;default:failure" json:"notify_on"` // always, failure, success
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Script *Script `json:"script,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (CronJob) TableName() string {
|
||||
return "cron_jobs"
|
||||
}
|
||||
|
||||
// Script 脚本库模型
|
||||
type Script struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Type string `gorm:"size:32;default:shell" json:"type"` // shell, python, powershell, yaml
|
||||
Content string `gorm:"type:text;not null" json:"content"`
|
||||
Params string `gorm:"type:text" json:"params"` // JSON
|
||||
Timeout int `gorm:"default:300" json:"timeout"`
|
||||
Version int `gorm:"default:1" json:"version"`
|
||||
RunCount int `gorm:"default:0" json:"run_count"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
UpdatedBy uint `json:"updated_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Script) TableName() string {
|
||||
return "scripts"
|
||||
}
|
||||
|
||||
// TaskExecution 任务执行记录
|
||||
type TaskExecution struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TaskType string `gorm:"size:32;not null" json:"task_type"` // cron, script, playbook
|
||||
TaskID uint `json:"task_id"`
|
||||
TaskName string `gorm:"size:128" json:"task_name"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, running, success, failed, cancelled
|
||||
TargetType string `gorm:"size:32" json:"target_type"`
|
||||
Targets string `gorm:"type:text" json:"targets"`
|
||||
Output string `gorm:"type:longtext" json:"output"`
|
||||
Error string `gorm:"type:text" json:"error"`
|
||||
Duration int `json:"duration"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
FinishedAt *time.Time `json:"finished_at"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (TaskExecution) TableName() string {
|
||||
return "task_executions"
|
||||
}
|
||||
|
||||
// Playbook Ansible Playbook模型
|
||||
type Playbook struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Content string `gorm:"type:text;not null" json:"content"`
|
||||
Variables string `gorm:"type:text" json:"variables"`
|
||||
Inventory string `gorm:"type:text" json:"inventory"`
|
||||
Timeout int `gorm:"default:600" json:"timeout"`
|
||||
RunCount int `gorm:"default:0" json:"run_count"`
|
||||
CreatedBy uint `json:"created_by"`
|
||||
UpdatedBy uint `json:"updated_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Playbook) TableName() string {
|
||||
return "playbooks"
|
||||
}
|
||||
|
||||
// CreateCronJobRequest 创建定时任务请求
|
||||
type CreateCronJobRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
CronExpr string `json:"cron_expr" binding:"required"`
|
||||
Type string `json:"type" binding:"required,oneof=script command playbook"`
|
||||
Content string `json:"content"`
|
||||
ScriptID *uint `json:"script_id"`
|
||||
TargetType string `json:"target_type" binding:"omitempty,oneof=server group tag"`
|
||||
Targets []uint `json:"targets"`
|
||||
Timeout int `json:"timeout"`
|
||||
NotifyOn string `json:"notify_on" binding:"omitempty,oneof=always failure success"`
|
||||
}
|
||||
|
||||
// CreateScriptRequest 创建脚本请求
|
||||
type CreateScriptRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type" binding:"omitempty,oneof=shell python powershell yaml"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
Params string `json:"params"`
|
||||
Timeout int `json:"timeout"`
|
||||
}
|
||||
|
||||
// ExecuteScriptRequest 执行脚本请求
|
||||
type ExecuteScriptRequest struct {
|
||||
TargetType string `json:"target_type" binding:"required,oneof=server group tag"`
|
||||
Targets []uint `json:"targets" binding:"required"`
|
||||
Params map[string]string `json:"params"`
|
||||
}
|
||||
|
||||
// AutomationStats 自动化统计
|
||||
type AutomationStats struct {
|
||||
CronJobCount int64 `json:"cron_job_count"`
|
||||
ScriptCount int64 `json:"script_count"`
|
||||
PlaybookCount int64 `json:"playbook_count"`
|
||||
TodayExecutions int64 `json:"today_executions"`
|
||||
SuccessRate float64 `json:"success_rate"`
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Pipeline CI/CD流水线模型
|
||||
type Pipeline struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Type string `gorm:"size:32;default:deploy" json:"type"` // build, deploy, test
|
||||
Source string `gorm:"size:255" json:"source"` // Git仓库地址
|
||||
Branch string `gorm:"size:64;default:main" json:"branch"`
|
||||
Dockerfile string `gorm:"size:255" json:"dockerfile"`
|
||||
Stages string `gorm:"type:text" json:"stages"` // JSON
|
||||
Variables string `gorm:"type:text" json:"variables"` // JSON
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
LastRunAt *time.Time `json:"last_run_at"`
|
||||
LastStatus string `gorm:"size:32" json:"last_status"`
|
||||
RunCount int `gorm:"default:0" json:"run_count"`
|
||||
SuccessCount int `gorm:"default:0" json:"success_count"`
|
||||
FailCount int `gorm:"default:0" json:"fail_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Pipeline) TableName() string {
|
||||
return "pipelines"
|
||||
}
|
||||
|
||||
// PipelineRun 流水线运行记录
|
||||
type PipelineRun struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
PipelineID uint `gorm:"not null" json:"pipeline_id"`
|
||||
BuildNumber int `json:"build_number"`
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, running, success, failed, cancelled
|
||||
Branch string `gorm:"size:64" json:"branch"`
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
Duration int `json:"duration"` // 秒
|
||||
Stages string `gorm:"type:text" json:"stages"` // JSON
|
||||
Logs string `gorm:"type:longtext" json:"logs"`
|
||||
TriggeredBy string `gorm:"size:64" json:"triggered_by"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
FinishedAt *time.Time `json:"finished_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Pipeline *Pipeline `json:"pipeline,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (PipelineRun) TableName() string {
|
||||
return "pipeline_runs"
|
||||
}
|
||||
|
||||
// AppRelease 应用发布模型
|
||||
type AppRelease struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
AppName string `gorm:"size:128;not null" json:"app_name"`
|
||||
Version string `gorm:"size:64;not null" json:"version"`
|
||||
Environment string `gorm:"size:32;not null" json:"environment"` // dev, test, staging, prod
|
||||
Status string `gorm:"size:32;default:pending" json:"status"` // pending, building, deploying, success, failed, rolled_back
|
||||
CommitID string `gorm:"size:64" json:"commit_id"`
|
||||
CommitMsg string `gorm:"size:500" json:"commit_msg"`
|
||||
Author string `gorm:"size:64" json:"author"`
|
||||
Approver string `gorm:"size:64" json:"approver"`
|
||||
ApprovedAt *time.Time `json:"approved_at"`
|
||||
DeployedAt *time.Time `json:"deployed_at"`
|
||||
RollbackAt *time.Time `json:"rollback_at"`
|
||||
Duration int `json:"duration"`
|
||||
Servers string `gorm:"type:text" json:"servers"` // JSON
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (AppRelease) TableName() string {
|
||||
return "app_releases"
|
||||
}
|
||||
|
||||
// CreatePipelineRequest 创建流水线请求
|
||||
type CreatePipelineRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type" binding:"omitempty,oneof=build deploy test"`
|
||||
Source string `json:"source"`
|
||||
Branch string `json:"branch"`
|
||||
Dockerfile string `json:"dockerfile"`
|
||||
Stages string `json:"stages"`
|
||||
Variables string `json:"variables"`
|
||||
}
|
||||
|
||||
// TriggerPipelineRequest 触发流水线请求
|
||||
type TriggerPipelineRequest struct {
|
||||
Branch string `json:"branch"`
|
||||
Variables map[string]string `json:"variables"`
|
||||
}
|
||||
|
||||
// CreateAppReleaseRequest 创建应用发布请求
|
||||
type CreateAppReleaseRequest struct {
|
||||
AppName string `json:"app_name" binding:"required"`
|
||||
Version string `json:"version" binding:"required"`
|
||||
Environment string `json:"environment" binding:"required,oneof=dev test staging prod"`
|
||||
CommitID string `json:"commit_id"`
|
||||
CommitMsg string `json:"commit_msg"`
|
||||
Servers []uint `json:"servers"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// PipelineStats 流水线统计
|
||||
type PipelineStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Success int64 `json:"success"`
|
||||
Failed int64 `json:"failed"`
|
||||
Running int64 `json:"running"`
|
||||
TodayCount int64 `json:"today_count"`
|
||||
SuccessRate float64 `json:"success_rate"`
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package models
|
||||
|
||||
// Response 通用响应
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
// ListResponse 列表响应
|
||||
type ListResponse struct {
|
||||
List interface{} `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// PageQuery 分页查询
|
||||
type PageQuery struct {
|
||||
Page int `form:"page,default=1"`
|
||||
PageSize int `form:"page_size,default=20"`
|
||||
Keyword string `form:"keyword"`
|
||||
Sort string `form:"sort"`
|
||||
Order string `form:"order,default=desc"`
|
||||
}
|
||||
|
||||
// GetOffset 获取偏移量
|
||||
func (p *PageQuery) GetOffset() int {
|
||||
if p.Page < 1 {
|
||||
p.Page = 1
|
||||
}
|
||||
return (p.Page - 1) * p.GetLimit()
|
||||
}
|
||||
|
||||
// GetLimit 获取每页数量
|
||||
func (p *PageQuery) GetLimit() int {
|
||||
if p.PageSize < 1 {
|
||||
p.PageSize = 20
|
||||
}
|
||||
if p.PageSize > 100 {
|
||||
p.PageSize = 100
|
||||
}
|
||||
return p.PageSize
|
||||
}
|
||||
|
||||
// IDRequest ID请求
|
||||
type IDRequest struct {
|
||||
ID uint `uri:"id" binding:"required"`
|
||||
}
|
||||
|
||||
// IDsRequest IDs请求
|
||||
type IDsRequest struct {
|
||||
IDs []uint `json:"ids" binding:"required"`
|
||||
}
|
||||
|
||||
// StatusRequest 状态请求
|
||||
type StatusRequest struct {
|
||||
Status int `json:"status" binding:"required,oneof=0 1"`
|
||||
}
|
||||
|
||||
// DashboardStats 仪表盘统计
|
||||
type DashboardStats struct {
|
||||
ServerStats ServerStats `json:"server_stats"`
|
||||
K8sStats K8sClusterStats `json:"k8s_stats"`
|
||||
AlertStats AlertStats `json:"alert_stats"`
|
||||
PipelineStats PipelineStats `json:"pipeline_stats"`
|
||||
CostStats CostStats `json:"cost_stats"`
|
||||
TopResourceUsage TopResourceUsage `json:"top_resource_usage"`
|
||||
ExpiringCerts []DomainCert `json:"expiring_certs"`
|
||||
}
|
||||
|
||||
// CostStats 成本统计
|
||||
type CostStats struct {
|
||||
TotalCost float64 `json:"total_cost"`
|
||||
MonthCost float64 `json:"month_cost"`
|
||||
CloudCosts []CloudCost `json:"cloud_costs"`
|
||||
MonthTrend []MonthTrend `json:"month_trend"`
|
||||
}
|
||||
|
||||
// CloudCost 云平台成本
|
||||
type CloudCost struct {
|
||||
Cloud string `json:"cloud"`
|
||||
Cost float64 `json:"cost"`
|
||||
}
|
||||
|
||||
// MonthTrend 月度趋势
|
||||
type MonthTrend struct {
|
||||
Month string `json:"month"`
|
||||
Cost float64 `json:"cost"`
|
||||
}
|
||||
|
||||
// TopResourceUsage Top资源使用
|
||||
type TopResourceUsage struct {
|
||||
CPU []ServerResource `json:"cpu"`
|
||||
Memory []ServerResource `json:"memory"`
|
||||
Disk []ServerResource `json:"disk"`
|
||||
}
|
||||
|
||||
// ServerResource 服务器资源
|
||||
type ServerResource struct {
|
||||
ID uint `json:"id"`
|
||||
Hostname string `json:"hostname"`
|
||||
IP string `json:"ip"`
|
||||
Usage float64 `json:"usage"`
|
||||
}
|
||||
|
||||
// DomainCert 域名证书
|
||||
type DomainCert struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ExpireDate string `json:"expire_date"`
|
||||
DaysUntilExpiry int `json:"days_until_expiry"`
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// K8sCluster K8s集群模型
|
||||
type K8sCluster struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Version string `gorm:"size:32" json:"version"`
|
||||
Status string `gorm:"size:32;default:healthy" json:"status"` // healthy, warning, error
|
||||
APIEndpoint string `gorm:"size:255" json:"api_endpoint"`
|
||||
KubeConfig string `gorm:"type:text" json:"-"`
|
||||
NodeCount int `gorm:"default:0" json:"node_count"`
|
||||
PodCount int `gorm:"default:0" json:"pod_count"`
|
||||
ServiceCount int `gorm:"default:0" json:"service_count"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
Labels string `gorm:"type:text" json:"labels"` // JSON
|
||||
LastSyncAt *time.Time `json:"last_sync_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (K8sCluster) TableName() string {
|
||||
return "k8s_clusters"
|
||||
}
|
||||
|
||||
// K8sNode K8s节点模型
|
||||
type K8sNode struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
IP string `gorm:"size:64" json:"ip"`
|
||||
Role string `gorm:"size:32" json:"role"` // master, worker
|
||||
Status string `gorm:"size:32" json:"status"`
|
||||
OS string `gorm:"size:64" json:"os"`
|
||||
KubeletVer string `gorm:"size:32" json:"kubelet_version"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
DiskUsage float64 `json:"disk_usage"`
|
||||
PodCount int `json:"pod_count"`
|
||||
MaxPods int `json:"max_pods"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Cluster *K8sCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (K8sNode) TableName() string {
|
||||
return "k8s_nodes"
|
||||
}
|
||||
|
||||
// K8sPod K8s Pod模型
|
||||
type K8sPod struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Status string `gorm:"size:32" json:"status"` // Running, Pending, Succeeded, Failed
|
||||
NodeName string `gorm:"size:128" json:"node_name"`
|
||||
IP string `gorm:"size:64" json:"ip"`
|
||||
RestartCount int `json:"restart_count"`
|
||||
Image string `gorm:"size:255" json:"image"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Cluster *K8sCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (K8sPod) TableName() string {
|
||||
return "k8s_pods"
|
||||
}
|
||||
|
||||
// K8sDeployment K8s Deployment模型
|
||||
type K8sDeployment struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Replicas int `json:"replicas"`
|
||||
AvailableReplicas int `json:"available_replicas"`
|
||||
ReadyReplicas int `json:"ready_replicas"`
|
||||
Image string `gorm:"size:255" json:"image"`
|
||||
Strategy string `gorm:"size:32" json:"strategy"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Cluster *K8sCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (K8sDeployment) TableName() string {
|
||||
return "k8s_deployments"
|
||||
}
|
||||
|
||||
// K8sService K8s Service模型
|
||||
type K8sService struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Type string `gorm:"size:32" json:"type"` // ClusterIP, NodePort, LoadBalancer
|
||||
ClusterIP string `gorm:"size:64" json:"cluster_ip"`
|
||||
ExternalIP string `gorm:"size:255" json:"external_ip"`
|
||||
Ports string `gorm:"type:text" json:"ports"` // JSON
|
||||
Selector string `gorm:"type:text" json:"selector"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Cluster *K8sCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (K8sService) TableName() string {
|
||||
return "k8s_services"
|
||||
}
|
||||
|
||||
// K8sIngress K8s Ingress模型
|
||||
type K8sIngress struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ClusterID uint `gorm:"not null" json:"cluster_id"`
|
||||
Namespace string `gorm:"size:64;not null" json:"namespace"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Hosts string `gorm:"type:text" json:"hosts"` // JSON
|
||||
Backend string `gorm:"size:255" json:"backend"`
|
||||
TLS bool `json:"tls"`
|
||||
TLSHosts string `gorm:"type:text" json:"tls_hosts"`
|
||||
Labels string `gorm:"type:text" json:"labels"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Cluster *K8sCluster `json:"cluster,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (K8sIngress) TableName() string {
|
||||
return "k8s_ingresses"
|
||||
}
|
||||
|
||||
// CreateK8sClusterRequest 创建K8s集群请求
|
||||
type CreateK8sClusterRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
Version string `json:"version"`
|
||||
APIEndpoint string `json:"api_endpoint"`
|
||||
KubeConfig string `json:"kube_config"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// K8sClusterStats K8s集群统计
|
||||
type K8sClusterStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Healthy int64 `json:"healthy"`
|
||||
Warning int64 `json:"warning"`
|
||||
Error int64 `json:"error"`
|
||||
TotalNodes int64 `json:"total_nodes"`
|
||||
TotalPods int64 `json:"total_pods"`
|
||||
TotalServices int64 `json:"total_services"`
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// NavigationGroup 导航分组模型
|
||||
type NavigationGroup struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
LinkCount int `gorm:"default:0" json:"link_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (NavigationGroup) TableName() string {
|
||||
return "navigation_groups"
|
||||
}
|
||||
|
||||
// NavigationLink 导航链接模型
|
||||
type NavigationLink struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
GroupID uint `json:"group_id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
URL string `gorm:"size:500;not null" json:"url"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Icon string `gorm:"size:64" json:"icon"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON
|
||||
IsFavorite bool `gorm:"default:false" json:"is_favorite"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Group *NavigationGroup `json:"group,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (NavigationLink) TableName() string {
|
||||
return "navigation_links"
|
||||
}
|
||||
|
||||
// CreateNavigationGroupRequest 创建导航分组请求
|
||||
type CreateNavigationGroupRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
Sort int `json:"sort"`
|
||||
}
|
||||
|
||||
// UpdateNavigationGroupRequest 更新导航分组请求
|
||||
type UpdateNavigationGroupRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
Sort int `json:"sort"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// CreateNavigationLinkRequest 创建导航链接请求
|
||||
type CreateNavigationLinkRequest struct {
|
||||
GroupID uint `json:"group_id" binding:"required"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
URL string `json:"url" binding:"required,url"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
Tags []string `json:"tags"`
|
||||
Sort int `json:"sort"`
|
||||
}
|
||||
|
||||
// UpdateNavigationLinkRequest 更新导航链接请求
|
||||
type UpdateNavigationLinkRequest struct {
|
||||
GroupID uint `json:"group_id"`
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url" binding:"omitempty,url"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
Tags []string `json:"tags"`
|
||||
Sort int `json:"sort"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// ToggleFavoriteRequest 切换收藏请求
|
||||
type ToggleFavoriteRequest struct {
|
||||
IsFavorite bool `json:"is_favorite"`
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Server 服务器模型
|
||||
type Server struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Hostname string `gorm:"size:128;not null" json:"hostname"`
|
||||
IP string `gorm:"size:64;not null" json:"ip"`
|
||||
PublicIP string `gorm:"size:64" json:"public_ip"`
|
||||
Port int `gorm:"default:22" json:"port"`
|
||||
Username string `gorm:"size:64;default:root" json:"username"`
|
||||
Password string `gorm:"size:255" json:"-"`
|
||||
SSHKey string `gorm:"type:text" json:"-"`
|
||||
AuthType string `gorm:"size:32;default:password" json:"auth_type"` // password, key
|
||||
OS string `gorm:"size:64" json:"os"`
|
||||
OSVersion string `gorm:"size:64" json:"os_version"`
|
||||
Arch string `gorm:"size:32" json:"arch"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"` // MB
|
||||
Disk int64 `json:"disk"` // GB
|
||||
Status string `gorm:"size:32;default:stopped" json:"status"` // running, stopped, maintenance, error
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
DiskUsage float64 `json:"disk_usage"`
|
||||
Uptime int64 `json:"uptime"` // seconds
|
||||
AgentVersion string `gorm:"size:32" json:"agent_version"`
|
||||
AgentStatus string `gorm:"size:32;default:offline" json:"agent_status"` // online, offline
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `gorm:"type:text" json:"tags"` // JSON
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
LastCheckAt *time.Time `json:"last_check_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Region *Region `json:"region,omitempty"`
|
||||
Cloud *Cloud `json:"cloud,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Server) TableName() string {
|
||||
return "servers"
|
||||
}
|
||||
|
||||
// Cloud 云平台模型
|
||||
type Cloud struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Type string `gorm:"size:32;default:public" json:"type"` // public, private, hybrid
|
||||
Status string `gorm:"size:32;default:active" json:"status"`
|
||||
Website string `gorm:"size:255" json:"website"`
|
||||
Description string `gorm:"size:500" json:"description"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Cloud) TableName() string {
|
||||
return "clouds"
|
||||
}
|
||||
|
||||
// CloudAccount 云账号模型
|
||||
type CloudAccount struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:128;not null" json:"name"`
|
||||
Provider string `gorm:"size:64;not null" json:"provider"` // aws, aliyun, tencent, huawei, azure
|
||||
AccessKey string `gorm:"size:255;not null" json:"-"`
|
||||
SecretKey string `gorm:"size:255;not null" json:"-"`
|
||||
Status string `gorm:"size:32;default:active" json:"status"` // active, inactive, error
|
||||
RegionCount int `gorm:"default:0" json:"region_count"`
|
||||
ServerCount int `gorm:"default:0" json:"server_count"`
|
||||
LastSyncAt *time.Time `json:"last_sync_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (CloudAccount) TableName() string {
|
||||
return "cloud_accounts"
|
||||
}
|
||||
|
||||
// Region 区域模型
|
||||
type Region struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Provider string `gorm:"size:64;not null" json:"provider"`
|
||||
Location string `gorm:"size:128" json:"location"`
|
||||
Status string `gorm:"size:32;default:active" json:"status"`
|
||||
Endpoint string `gorm:"size:255" json:"endpoint"`
|
||||
VPCCount int `gorm:"default:0" json:"vpc_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Region) TableName() string {
|
||||
return "regions"
|
||||
}
|
||||
|
||||
// Domain 域名模型
|
||||
type Domain struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:255;uniqueIndex;not null" json:"name"`
|
||||
Registrar string `gorm:"size:128" json:"registrar"`
|
||||
Status string `gorm:"size:32;default:active" json:"status"` // active, expired, pending
|
||||
ExpireDate *time.Time `json:"expire_date"`
|
||||
DNSProvider string `gorm:"size:128" json:"dns_provider"`
|
||||
RecordCount int `gorm:"default:0" json:"record_count"`
|
||||
SSLEnabled bool `gorm:"default:false" json:"ssl_enabled"`
|
||||
SSLExpireDate *time.Time `json:"ssl_expire_date"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Domain) TableName() string {
|
||||
return "domains"
|
||||
}
|
||||
|
||||
// CreateServerRequest 创建服务器请求
|
||||
type CreateServerRequest struct {
|
||||
Hostname string `json:"hostname" binding:"required"`
|
||||
IP string `json:"ip" binding:"required,ip"`
|
||||
PublicIP string `json:"public_ip" binding:"omitempty,ip"`
|
||||
Port int `json:"port" binding:"omitempty,min=1,max=65535"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
SSHKey string `json:"ssh_key"`
|
||||
AuthType string `json:"auth_type" binding:"omitempty,oneof=password key"`
|
||||
OS string `json:"os"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `json:"tags"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// UpdateServerRequest 更新服务器请求
|
||||
type UpdateServerRequest struct {
|
||||
Hostname string `json:"hostname"`
|
||||
PublicIP string `json:"public_ip" binding:"omitempty,ip"`
|
||||
Port int `json:"port" binding:"omitempty,min=1,max=65535"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
SSHKey string `json:"ssh_key"`
|
||||
AuthType string `json:"auth_type" binding:"omitempty,oneof=password key"`
|
||||
OS string `json:"os"`
|
||||
CPU int `json:"cpu"`
|
||||
Memory int64 `json:"memory"`
|
||||
Disk int64 `json:"disk"`
|
||||
Status string `json:"status" binding:"omitempty,oneof=running stopped maintenance error"`
|
||||
RegionID *uint `json:"region_id"`
|
||||
CloudID *uint `json:"cloud_id"`
|
||||
Tags string `json:"tags"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// ServerListResponse 服务器列表响应
|
||||
type ServerListResponse struct {
|
||||
List []Server `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// ServerStats 服务器统计
|
||||
type ServerStats struct {
|
||||
Total int64 `json:"total"`
|
||||
Running int64 `json:"running"`
|
||||
Stopped int64 `json:"stopped"`
|
||||
Maintenance int64 `json:"maintenance"`
|
||||
Error int64 `json:"error"`
|
||||
AvgCPU float64 `json:"avg_cpu"`
|
||||
AvgMemory float64 `json:"avg_memory"`
|
||||
AvgDisk float64 `json:"avg_disk"`
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// User 用户模型
|
||||
type User struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Username string `gorm:"size:64;uniqueIndex;not null" json:"username"`
|
||||
Password string `gorm:"size:255;not null" json:"-"`
|
||||
Email string `gorm:"size:128;uniqueIndex" json:"email"`
|
||||
Phone string `gorm:"size:32" json:"phone"`
|
||||
RealName string `gorm:"size:64" json:"real_name"`
|
||||
Avatar string `gorm:"size:255" json:"avatar"`
|
||||
Status int `gorm:"default:1" json:"status"` // 0:禁用 1:启用
|
||||
IsAdmin bool `gorm:"default:false" json:"is_admin"`
|
||||
LastLogin *time.Time `json:"last_login"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Roles []Role `gorm:"many2many:user_roles;" json:"roles,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (User) TableName() string {
|
||||
return "users"
|
||||
}
|
||||
|
||||
// Role 角色模型
|
||||
type Role struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
|
||||
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Role) TableName() string {
|
||||
return "roles"
|
||||
}
|
||||
|
||||
// Permission 权限模型
|
||||
type Permission struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"size:64;not null" json:"name"`
|
||||
Code string `gorm:"size:128;uniqueIndex;not null" json:"code"`
|
||||
Type string `gorm:"size:32" json:"type"` // menu, button, api
|
||||
Path string `gorm:"size:255" json:"path"`
|
||||
Method string `gorm:"size:32" json:"method"`
|
||||
ParentID *uint `json:"parent_id"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Permission) TableName() string {
|
||||
return "permissions"
|
||||
}
|
||||
|
||||
// LoginRequest 登录请求
|
||||
type LoginRequest struct {
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
|
||||
// LoginResponse 登录响应
|
||||
type LoginResponse struct {
|
||||
Token string `json:"token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
// CreateUserRequest 创建用户请求
|
||||
type CreateUserRequest struct {
|
||||
Username string `json:"username" binding:"required,min=3,max=64"`
|
||||
Password string `json:"password" binding:"required,min=6,max=32"`
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Phone string `json:"phone"`
|
||||
RealName string `json:"real_name"`
|
||||
RoleIDs []uint `json:"role_ids"`
|
||||
}
|
||||
|
||||
// UpdateUserRequest 更新用户请求
|
||||
type UpdateUserRequest struct {
|
||||
Email string `json:"email" binding:"omitempty,email"`
|
||||
Phone string `json:"phone"`
|
||||
RealName string `json:"real_name"`
|
||||
Status *int `json:"status"`
|
||||
RoleIDs []uint `json:"role_ids"`
|
||||
}
|
||||
|
||||
// ChangePasswordRequest 修改密码请求
|
||||
type ChangePasswordRequest struct {
|
||||
OldPassword string `json:"old_password" binding:"required"`
|
||||
NewPassword string `json:"new_password" binding:"required,min=6,max=32"`
|
||||
}
|
||||
Reference in new issue
Block a user