Documentation
¶
Index ¶
- Constants
- type Agent
- type AgentRegisterRequest
- type AgentTask
- type AgentTaskResult
- type AgentToken
- type CleanConfig
- type Dependency
- type EnvironmentVariable
- type Language
- type LocalTime
- type LoginLog
- type RepoConfig
- type Script
- type SendStats
- type Setting
- type Task
- func (t *Task) GetCommand() string
- func (t *Task) GetEnvs() string
- func (t *Task) GetID() string
- func (t *Task) GetLanguages() []map[string]string
- func (t *Task) GetName() string
- func (t *Task) GetRandomRange() int
- func (t *Task) GetSchedule() string
- func (t *Task) GetTimeout() int
- func (t *Task) GetUseMise() bool
- func (t *Task) GetWorkDir() string
- func (Task) TableName() string
- func (t *Task) UseMise() bool
- type TaskConfig
- type TaskLog
- type User
Constants ¶
View Source
const TimeFormat = "2006-01-02 15:04:05"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:100;not null"` // Agent 名称
Token string `json:"token" gorm:"size:64;index"` // 认证 Token(可重复使用)
MachineID string `json:"machine_id" gorm:"size:64;uniqueIndex"` // 机器识别码(唯一)
Description string `json:"description" gorm:"size:255"` // 描述
Status string `json:"status" gorm:"size:20;default:'pending';index"` // 状态: constant.AgentStatusOnline, constant.AgentStatusOffline
LastSeen *LocalTime `json:"last_seen"` // 最后心跳时间
IP string `json:"ip" gorm:"size:45"` // Agent IP 地址
Version string `json:"version" gorm:"size:50"` // Agent 版本
BuildTime string `json:"build_time" gorm:"size:30"` // Agent 构建时间
Hostname string `json:"hostname" gorm:"size:100"` // Agent 主机名
OS string `json:"os" gorm:"size:20"` // 操作系统
Arch string `json:"arch" gorm:"size:20"` // 架构
ForceUpdate bool `json:"force_update" gorm:"default:false"` // 强制更新标志
Enabled bool `json:"enabled" gorm:"default:true"` // 是否启用
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
Agent 远程执行代理
type AgentRegisterRequest ¶
type AgentRegisterRequest struct {
Name string `json:"name"`
Hostname string `json:"hostname"`
Version string `json:"version"`
BuildTime string `json:"build_time"`
Token string `json:"token"` // 注册令牌
MachineID string `json:"machine_id"` // 机器识别码
}
AgentRegisterRequest Agent 注册请求
type AgentTask ¶
type AgentTask struct {
ID uint `json:"id"`
Name string `json:"name"`
Command string `json:"command"`
Schedule string `json:"schedule"`
Timeout int `json:"timeout"`
WorkDir string `json:"work_dir"`
Envs string `json:"envs"`
Languages []map[string]string `json:"languages"`
RandomRange int `json:"random_range"`
Enabled bool `json:"enabled"`
}
AgentTask Agent 任务配置(用于下发给 Agent)
func (AgentTask) GetCommand ¶ added in v1.0.10
func (AgentTask) GetRandomRange ¶ added in v1.0.10
func (AgentTask) GetSchedule ¶ added in v1.0.10
type AgentTaskResult ¶
type AgentTaskResult struct {
TaskID uint `json:"task_id"`
LogID uint `json:"log_id"`
AgentID uint `json:"agent_id"`
Command string `json:"command"`
Output string `json:"output"`
Error string `json:"error"` // 额外的系统错误信息
Status string `json:"status"` // success, failed
Duration int64 `json:"duration"` // 耗时(毫秒)
ExitCode int `json:"exit_code"`
StartTime int64 `json:"start_time"` // Unix 时间戳
EndTime int64 `json:"end_time"` // Unix 时间戳
}
AgentTaskResult Agent 上报的任务执行结果
type AgentToken ¶
type AgentToken struct {
ID uint `json:"id" gorm:"primaryKey"`
Token string `json:"token" gorm:"size:64;uniqueIndex;not null"` // 令牌
Remark string `json:"remark" gorm:"size:255"` // 备注
MaxUses int `json:"max_uses" gorm:"default:0"` // 最大使用次数,0 表示无限制
UsedCount int `json:"used_count" gorm:"default:0"` // 已使用次数
ExpiresAt *LocalTime `json:"expires_at"` // 过期时间,null 表示永不过期
Enabled bool `json:"enabled" gorm:"default:true"` // 是否启用
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
AgentToken Agent 令牌
func (AgentToken) TableName ¶
func (AgentToken) TableName() string
type CleanConfig ¶
type CleanConfig struct {
Type string `json:"type"` // "day" 或 "count"
Keep int `json:"keep"` // 保留天数或条数
}
CleanConfig 清理配置结构
type Dependency ¶
type Dependency struct {
ID int `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:100;not null"`
Version string `json:"version" gorm:"size:50"`
Language string `json:"language" gorm:"size:100;index"` // 关联语言 (node, python...)
LangVersion string `json:"lang_version" gorm:"size:100;index"` // 关联语言版本
Remark string `json:"remark" gorm:"size:255"`
Log string `json:"log" gorm:"type:text"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Dependency 依赖包模型
func (Dependency) TableName ¶
func (Dependency) TableName() string
type EnvironmentVariable ¶
type EnvironmentVariable struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:255;not null"`
Value string `json:"value" gorm:"type:text"`
Remark string `json:"remark" gorm:"size:500"`
Hidden bool `json:"hidden" gorm:"default:true"`
UserID uint `json:"user_id" gorm:"index"`
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
EnvironmentVariable represents an environment variable
func (EnvironmentVariable) TableName ¶
func (EnvironmentVariable) TableName() string
type Language ¶
type Language struct {
ID uint `json:"id" gorm:"primaryKey"`
Plugin string `json:"plugin" gorm:"size:100;not null;index"`
Version string `json:"version" gorm:"size:100;not null;index"`
InstallPath string `json:"install_path" gorm:"size:255"`
Source string `json:"source" gorm:"size:255"`
InstalledAt *LocalTime `json:"installed_at"`
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
type LocalTime ¶
LocalTime 自定义时间类型,JSON 序列化为 "年-月-日 时:分:秒" 格式
func (LocalTime) MarshalJSON ¶
func (*LocalTime) UnmarshalJSON ¶
type LoginLog ¶
type LoginLog struct {
ID uint `json:"id" gorm:"primaryKey"`
Username string `json:"username" gorm:"size:100;index;not null"`
IP string `json:"ip" gorm:"size:50"`
UserAgent string `json:"user_agent" gorm:"size:500"`
Status string `json:"status" gorm:"size:20;index"` // success, failed
Message string `json:"message" gorm:"size:255"`
CreatedAt LocalTime `json:"created_at" gorm:"index"`
}
LoginLog 登录日志
type RepoConfig ¶
type RepoConfig struct {
SourceType string `json:"source_type"` // url 或 git
SourceURL string `json:"source_url"` // 源地址
TargetPath string `json:"target_path"` // 目标路径
Branch string `json:"branch"` // Git 分支
SparsePath string `json:"sparse_path"` // 稀疏检出路径(仅拉取指定目录或文件)
SingleFile bool `json:"single_file"` // 单文件模式(直接下载文件而非 sparse-checkout)
Proxy string `json:"proxy"` // 代理类型: none, ghproxy, mirror, custom
ProxyURL string `json:"proxy_url"` // 自定义代理地址
AuthToken string `json:"auth_token"` // 认证 Token
}
RepoConfig 仓库同步配置
type Script ¶
type Script struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:255;not null"`
Content string `json:"content" gorm:"type:text"`
UserID uint `json:"user_id" gorm:"index"`
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
Script represents a script file
type SendStats ¶
type SendStats struct {
ID uint `json:"id" gorm:"primaryKey"`
TaskID uint `json:"task_id" gorm:"uniqueIndex:idx_task_day_status"`
Day string `json:"day" gorm:"size:10;uniqueIndex:idx_task_day_status"` // 格式: 2006-01-02
Status string `json:"status" gorm:"size:20;uniqueIndex:idx_task_day_status"`
Num int `json:"num" gorm:"default:0"`
}
SendStats 任务执行统计
type Setting ¶
type Setting struct {
ID uint `json:"id" gorm:"primaryKey"`
Section string `json:"section" gorm:"size:50;not null;index:idx_section_key"`
Key string `json:"key" gorm:"size:100;not null;index:idx_section_key"`
Value string `json:"value" gorm:"type:text"`
}
Setting 系统设置
type Task ¶
type Task struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:255;not null"`
Command string `json:"command" gorm:"type:text"` // 普通任务的命令
Tags string `json:"tags" gorm:"size:255;default:''"` // 标签,逗号分隔
Type string `json:"type" gorm:"size:20;default:'task'"` // 任务类型: constant.TaskTypeNormal, constant.TaskTypeRepo
TriggerType string `json:"trigger_type" gorm:"size:25;default:'cron'"` // 触发类型: constant.TriggerTypeCron, constant.TriggerTypeBaihuStartup
Config string `json:"config" gorm:"type:text"` // 配置 JSON(仓库同步配置等)
Schedule string `json:"schedule" gorm:"size:100"` // cron 表达式
Timeout int `json:"timeout" gorm:"default:30"` // 超时时间(分钟),默认30分钟
WorkDir string `json:"work_dir" gorm:"size:255;default:''"` // 工作目录,为空则使用 scripts 目录
CleanConfig string `json:"clean_config" gorm:"size:255;default:''"` // 清理配置 JSON
Envs string `json:"envs" gorm:"size:255;default:''"` // 环境变量ID列表,逗号分隔
Languages []map[string]string `json:"languages" gorm:"serializer:json;type:text"` // 针对本地任务的语言配置列表
AgentID *uint `json:"agent_id" gorm:"index"` // Agent ID,为空表示本地执行
RetryCount int `json:"retry_count" gorm:"default:0"` // 失败重试次数
RetryInterval int `json:"retry_interval" gorm:"default:0"` // 失败重试间隔(秒)
RandomRange int `json:"random_range" gorm:"default:0"` // 随机延迟范围(秒)
Enabled bool `json:"enabled" gorm:"default:true"`
RunningGo string `json:"running_go" gorm:"type:text"` // 正在运行的 go routine id 数组 (JSON)
LastRun *LocalTime `json:"last_run"`
NextRun *LocalTime `json:"next_run"`
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
Task 代表一个计划任务
func (*Task) GetCommand ¶
func (*Task) GetLanguages ¶
func (*Task) GetRandomRange ¶ added in v1.0.10
func (*Task) GetSchedule ¶
func (*Task) GetTimeout ¶
func (*Task) GetUseMise ¶
func (*Task) GetWorkDir ¶
type TaskConfig ¶
type TaskConfig struct {
Concurrency int `json:"$task_concurrency"` // 0: disable concurrency, 1: enable concurrency
}
TaskConfig 任务配置 RepoConfig+TaskConfig=task.config
type TaskLog ¶
type TaskLog struct {
ID uint `json:"id" gorm:"primaryKey"`
TaskID uint `json:"task_id" gorm:"index"`
AgentID *uint `json:"agent_id" gorm:"index"` // Agent ID,为空表示本地执行
Command string `json:"command" gorm:"type:text"`
Output string `json:"-" gorm:"type:longtext"` // gzip+base64 压缩后的日志
Error string `json:"error" gorm:"type:text"` // 额外的系统错误信息
Status string `json:"status" gorm:"size:20;index"` // success, failed
Duration int64 `json:"duration"` // 执行耗时(毫秒)
ExitCode int `json:"exit_code"`
StartTime *LocalTime `json:"start_time"`
EndTime *LocalTime `json:"end_time"`
CreatedAt LocalTime `json:"created_at"`
}
TaskLog 代表任务执行的日志记录
type User ¶
type User struct {
ID uint `json:"id" gorm:"primaryKey"`
Username string `json:"username" gorm:"size:100;uniqueIndex;not null"`
Password string `json:"-" gorm:"size:255;not null"`
Email string `json:"email" gorm:"size:255"`
Role string `json:"role" gorm:"size:20;default:user"` // admin, user
CreatedAt LocalTime `json:"created_at"`
UpdatedAt LocalTime `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
User represents a system user
Source Files
¶
Click to show internal directories.
Click to hide internal directories.