models

package
v1.3.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Page        = 1    // 当前页数
	PageSize    = 20   // 每页多少条数据
	MaxPageSize = 1000 // 每次最多取多少条
)
View Source
const (
	SlackCode        = "slack"
	SlackUrlKey      = "url"
	SlackTemplateKey = "template"
	SlackChannelKey  = "channel"
)
View Source
const (
	MailCode        = "mail"
	MailTemplateKey = "template"
	MailServerKey   = "server"
	MailUserKey     = "user"
)
View Source
const (
	WebhookCode        = "webhook"
	WebhookTemplateKey = "template"
	WebhookUrlKey      = "url"
)
View Source
const (
	SystemCode          = "system"
	LogRetentionDaysKey = "log_retention_days"
	LogCleanupTimeKey   = "log_cleanup_time"
	LogFileSizeLimitKey = "log_file_size_limit"
)
View Source
const DefaultTimeFormat = "2006-01-02 15:04:05"
View Source
const PasswordSaltLength = 6

Variables

View Source
var Db *gorm.DB
View Source
var TablePrefix = ""

Functions

func CreateDb

func CreateDb() *gorm.DB

创建Db

func CreateTmpDb

func CreateTmpDb(setting *setting.Setting) (*gorm.DB, error)

创建临时数据库连接

func RepairSettings added in v1.3.1

func RepairSettings() error

RepairSettings 修复缺失的 Setting 配置记录 用于解决数据库迁移或升级过程中可能出现的配置缺失问题

Types

type AgentToken added in v1.3.15

type AgentToken struct {
	Id        int        `json:"id" gorm:"primaryKey;autoIncrement"`
	Token     string     `json:"token" gorm:"type:varchar(64);uniqueIndex;not null"`
	ExpiresAt time.Time  `json:"expires_at" gorm:"not null"`
	Used      bool       `json:"used" gorm:"default:false"`
	UsedAt    *time.Time `json:"used_at" gorm:"default:null"`
	CreatedAt time.Time  `json:"created_at" gorm:"autoCreateTime"`
}

AgentToken agent注册token

func (*AgentToken) CleanExpired added in v1.3.15

func (t *AgentToken) CleanExpired() error

CleanExpired 清理过期token

func (*AgentToken) Create added in v1.3.15

func (t *AgentToken) Create() error

func (*AgentToken) FindByToken added in v1.3.15

func (t *AgentToken) FindByToken(token string) error

func (*AgentToken) IsValid added in v1.3.15

func (t *AgentToken) IsValid() bool

func (*AgentToken) MarkAsUsed added in v1.3.15

func (t *AgentToken) MarkAsUsed() error

type BaseModel

type BaseModel struct {
	Page     int `gorm:"-"`
	PageSize int `gorm:"-"`
}

type Channel

type Channel struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
}

type CommonMap

type CommonMap map[string]interface{}

type Host

type Host struct {
	Id        int16  `json:"id" gorm:"primaryKey;autoIncrement;type:smallint"`
	Name      string `json:"name" gorm:"type:varchar(64);not null"`
	Alias     string `json:"alias" gorm:"type:varchar(32);not null;default:''"`
	Port      int    `json:"port" gorm:"not null;default:5921"`
	Remark    string `json:"remark" gorm:"type:varchar(100);not null;default:''"`
	BaseModel `json:"-" gorm:"-"`
	Selected  bool `json:"-" gorm:"-"`
}

主机

func (*Host) AllList

func (host *Host) AllList() ([]Host, error)

func (*Host) Create

func (host *Host) Create() (insertId int16, err error)

新增

func (*Host) Delete

func (host *Host) Delete(id int) (int64, error)

删除

func (*Host) Find

func (host *Host) Find(id int) error

func (*Host) List

func (host *Host) List(params CommonMap) ([]Host, error)

func (*Host) NameExists

func (host *Host) NameExists(name string, id int16) (bool, error)

func (*Host) Total

func (host *Host) Total(params CommonMap) (int64, error)

func (*Host) Update

func (host *Host) Update(id int, data CommonMap) (int64, error)

更新

func (*Host) UpdateBean

func (host *Host) UpdateBean(id int16) (int64, error)

type LocalTime added in v1.3.1

type LocalTime time.Time

func (LocalTime) MarshalJSON added in v1.3.1

func (t LocalTime) MarshalJSON() ([]byte, error)

func (*LocalTime) Scan added in v1.3.1

func (t *LocalTime) Scan(value interface{}) error

func (*LocalTime) UnmarshalJSON added in v1.3.1

func (t *LocalTime) UnmarshalJSON(data []byte) error

func (LocalTime) Value added in v1.3.1

func (t LocalTime) Value() (driver.Value, error)

type LoginLog

type LoginLog struct {
	Id        int       `json:"id" gorm:"primaryKey;autoIncrement"`
	Username  string    `json:"username" gorm:"type:varchar(32);not null"`
	Ip        string    `json:"ip" gorm:"type:varchar(15);not null"`
	CreatedAt time.Time `json:"created" gorm:"column:created;autoCreateTime"`
	BaseModel `json:"-" gorm:"-"`
}

用户登录日志

func (*LoginLog) Create

func (log *LoginLog) Create() (insertId int, err error)

func (*LoginLog) List

func (log *LoginLog) List(params CommonMap) ([]LoginLog, error)

func (*LoginLog) Total

func (log *LoginLog) Total() (int64, error)

type Mail

type Mail struct {
	Host      string     `json:"host"`
	Port      int        `json:"port"`
	User      string     `json:"user"`
	Password  string     `json:"password"`
	MailUsers []MailUser `json:"mail_users"`
	Template  string     `json:"template"`
}

type MailUser

type MailUser struct {
	Id       int    `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
}

type Migration

type Migration struct{}

func (*Migration) Install

func (migration *Migration) Install(dbName string) error

首次安装, 创建数据库表

func (*Migration) Upgrade

func (migration *Migration) Upgrade(oldVersionId int)

迭代升级数据库, 新建表、新增字段等

type Setting

type Setting struct {
	Id    int    `gorm:"primaryKey;autoIncrement"`
	Code  string `gorm:"type:varchar(32);not null"`
	Key   string `gorm:"type:varchar(64);not null"`
	Value string `gorm:"type:varchar(4096);not null;default:''"`
}

func (*Setting) CreateChannel

func (setting *Setting) CreateChannel(channel string) (int64, error)

创建slack渠道

func (*Setting) CreateMailUser

func (setting *Setting) CreateMailUser(username, email string) (int64, error)

func (*Setting) GetLogCleanupTime

func (setting *Setting) GetLogCleanupTime() string

func (*Setting) GetLogFileSizeLimit

func (setting *Setting) GetLogFileSizeLimit() int

func (*Setting) GetLogRetentionDays

func (setting *Setting) GetLogRetentionDays() int

region 系统配置

func (*Setting) IsChannelExist

func (setting *Setting) IsChannelExist(channel string) bool

func (*Setting) Mail

func (setting *Setting) Mail() (Mail, error)

region 邮件配置

func (*Setting) RemoveChannel

func (setting *Setting) RemoveChannel(id int) (int64, error)

删除slack渠道

func (*Setting) RemoveMailUser

func (setting *Setting) RemoveMailUser(id int) (int64, error)

func (*Setting) Slack

func (setting *Setting) Slack() (Slack, error)

func (*Setting) UpdateLogCleanupTime

func (setting *Setting) UpdateLogCleanupTime(cleanupTime string) error

func (*Setting) UpdateLogFileSizeLimit

func (setting *Setting) UpdateLogFileSizeLimit(size int) error

func (*Setting) UpdateLogRetentionDays

func (setting *Setting) UpdateLogRetentionDays(days int) error

func (*Setting) UpdateMail

func (setting *Setting) UpdateMail(config, template string) error

func (*Setting) UpdateSlack

func (setting *Setting) UpdateSlack(url, template string) error

func (*Setting) UpdateWebHook

func (setting *Setting) UpdateWebHook(url, template string) error

func (*Setting) Webhook

func (setting *Setting) Webhook() (WebHook, error)

type Slack

type Slack struct {
	Url      string    `json:"url"`
	Channels []Channel `json:"channels"`
	Template string    `json:"template"`
}

type Status

type Status int8
const (
	Disabled Status = 0 // 禁用
	Failure  Status = 0 // 失败
	Enabled  Status = 1 // 启用
	Running  Status = 1 // 运行中
	Finish   Status = 2 // 完成
	Cancel   Status = 3 // 取消
)

type Task

type Task struct {
	Id               int                  `json:"id" gorm:"primaryKey;autoIncrement"`
	Name             string               `json:"name" gorm:"type:varchar(32);not null"`
	Level            TaskLevel            `json:"level" gorm:"type:tinyint;not null;index;default:1"`
	DependencyTaskId string               `json:"dependency_task_id" gorm:"type:varchar(64);not null;default:''"`
	DependencyStatus TaskDependencyStatus `json:"dependency_status" gorm:"type:tinyint;not null;default:1"`
	Spec             string               `json:"spec" gorm:"type:varchar(64);not null"`
	Protocol         TaskProtocol         `json:"protocol" gorm:"type:tinyint;not null;index"`
	Command          string               `json:"command" gorm:"type:varchar(256);not null"`
	HttpMethod       TaskHTTPMethod       `json:"http_method" gorm:"type:tinyint;not null;default:1"`
	Timeout          int                  `json:"timeout" gorm:"type:mediumint;not null;default:0"`
	Multi            int8                 `json:"multi" gorm:"type:tinyint;not null;default:1"`
	RetryTimes       int8                 `json:"retry_times" gorm:"type:tinyint;not null;default:0"`
	RetryInterval    int16                `json:"retry_interval" gorm:"type:smallint;not null;default:0"`
	NotifyStatus     int8                 `json:"notify_status" gorm:"type:tinyint;not null;default:1"`
	NotifyType       int8                 `json:"notify_type" gorm:"type:tinyint;not null;default:0"`
	NotifyReceiverId string               `json:"notify_receiver_id" gorm:"type:varchar(256);not null;default:''"`
	NotifyKeyword    string               `json:"notify_keyword" gorm:"type:varchar(128);not null;default:''"`
	Tag              string               `json:"tag" gorm:"type:varchar(32);not null;default:''"`
	Remark           string               `json:"remark" gorm:"type:varchar(100);not null;default:''"`
	Status           Status               `json:"status" gorm:"type:tinyint;not null;index;default:0"`
	CreatedAt        time.Time            `json:"created" gorm:"column:created;autoCreateTime"`
	DeletedAt        *time.Time           `json:"deleted" gorm:"column:deleted;index"`
	BaseModel        `json:"-" gorm:"-"`
	Hosts            []TaskHostDetail `json:"hosts" gorm:"-"`
	NextRunTime      time.Time        `json:"next_run_time" gorm:"-"`
}

任务

func (*Task) ActiveList

func (task *Task) ActiveList(page, pageSize int) ([]Task, error)

获取所有激活任务

func (*Task) ActiveListByHostId

func (task *Task) ActiveListByHostId(hostId int16) ([]Task, error)

获取某个主机下的所有激活任务

func (*Task) Create

func (task *Task) Create() (insertId int, err error)

新增

func (*Task) Delete

func (task *Task) Delete(id int) (int64, error)

删除

func (*Task) Detail

func (task *Task) Detail(id int) (Task, error)

func (*Task) Disable

func (task *Task) Disable(id int) (int64, error)

禁用

func (*Task) Enable

func (task *Task) Enable(id int) (int64, error)

激活

func (*Task) GetDependencyTaskList

func (task *Task) GetDependencyTaskList(ids string) ([]Task, error)

获取依赖任务列表

func (*Task) GetStatus

func (task *Task) GetStatus(id int) (Status, error)

func (*Task) List

func (task *Task) List(params CommonMap) ([]Task, error)

func (*Task) NameExist

func (task *Task) NameExist(name string, id int) (bool, error)

判断任务名称是否存在

func (*Task) Total

func (task *Task) Total(params CommonMap) (int64, error)

func (*Task) Update

func (task *Task) Update(id int, data CommonMap) (int64, error)

更新

func (*Task) UpdateBean

func (task *Task) UpdateBean(id int) (int64, error)

type TaskDependencyStatus

type TaskDependencyStatus int8
const (
	TaskDependencyStatusStrong TaskDependencyStatus = 1 // 强依赖
	TaskDependencyStatusWeak   TaskDependencyStatus = 2 // 弱依赖
)

type TaskHTTPMethod

type TaskHTTPMethod int8
const (
	TaskHTTPMethodGet  TaskHTTPMethod = 1
	TaskHttpMethodPost TaskHTTPMethod = 2
)

type TaskHost

type TaskHost struct {
	Id     int   `json:"id" gorm:"primaryKey;autoIncrement"`
	TaskId int   `json:"task_id" gorm:"not null;index"`
	HostId int16 `json:"host_id" gorm:"type:smallint;not null;index"`
}

func (*TaskHost) Add

func (th *TaskHost) Add(taskId int, hostIds []int) error

func (*TaskHost) GetHostIdsByTaskId

func (th *TaskHost) GetHostIdsByTaskId(taskId int) ([]TaskHostDetail, error)

func (*TaskHost) GetTaskIdsByHostId

func (th *TaskHost) GetTaskIdsByHostId(hostId int16) ([]interface{}, error)

func (*TaskHost) HostIdExist

func (th *TaskHost) HostIdExist(hostId int16) (bool, error)

判断主机id是否有引用

func (*TaskHost) Remove

func (th *TaskHost) Remove(taskId int) error

type TaskHostDetail

type TaskHostDetail struct {
	TaskHost
	Name  string `json:"name"`
	Port  int    `json:"port"`
	Alias string `json:"alias"`
}

func (TaskHostDetail) TableName

func (TaskHostDetail) TableName() string

type TaskLevel

type TaskLevel int8
const (
	TaskLevelParent TaskLevel = 1 // 父任务
	TaskLevelChild  TaskLevel = 2 // 子任务(依赖任务)
)

type TaskLog

type TaskLog struct {
	Id         int64        `json:"id" gorm:"primaryKey;autoIncrement;type:bigint"`
	TaskId     int          `json:"task_id" gorm:"not null;index;default:0"`
	Name       string       `json:"name" gorm:"type:varchar(32);not null"`
	Spec       string       `json:"spec" gorm:"type:varchar(64);not null"`
	Protocol   TaskProtocol `json:"protocol" gorm:"type:tinyint;not null;index"`
	Command    string       `json:"command" gorm:"type:varchar(256);not null"`
	Timeout    int          `json:"timeout" gorm:"type:mediumint;not null;default:0"`
	RetryTimes int8         `json:"retry_times" gorm:"type:tinyint;not null;default:0"`
	Hostname   string       `json:"hostname" gorm:"type:varchar(128);not null;default:''"`
	StartTime  LocalTime    `json:"start_time" gorm:"column:start_time;autoCreateTime"`
	EndTime    LocalTime    `json:"end_time" gorm:"column:end_time;autoUpdateTime"`
	Status     Status       `json:"status" gorm:"type:tinyint;not null;index;default:1"`
	Result     string       `json:"result" gorm:"type:mediumtext;not null"`
	TotalTime  int          `json:"total_time" gorm:"-"`
	BaseModel  `json:"-" gorm:"-"`
}

任务执行日志

func (*TaskLog) Clear

func (taskLog *TaskLog) Clear() (int64, error)

清空表

func (*TaskLog) Create

func (taskLog *TaskLog) Create() (insertId int64, err error)

func (*TaskLog) List

func (taskLog *TaskLog) List(params CommonMap) ([]TaskLog, error)

func (*TaskLog) Remove

func (taskLog *TaskLog) Remove(id int) (int64, error)

删除N个月前的日志

func (*TaskLog) RemoveByDays

func (taskLog *TaskLog) RemoveByDays(days int) (int64, error)

删除N天前的日志

func (*TaskLog) Total

func (taskLog *TaskLog) Total(params CommonMap) (int64, error)

func (*TaskLog) Update

func (taskLog *TaskLog) Update(id int64, data CommonMap) (int64, error)

更新

type TaskProtocol

type TaskProtocol int8
const (
	TaskHTTP TaskProtocol = iota + 1 // HTTP协议
	TaskRPC                          // RPC方式执行命令
)

type TaskType

type TaskType int8

type User

type User struct {
	Id           int       `json:"id" gorm:"primaryKey;autoIncrement"`
	Name         string    `json:"name" gorm:"type:varchar(32);not null;uniqueIndex"`
	Password     string    `json:"-" gorm:"type:char(32);not null"`
	Salt         string    `json:"-" gorm:"type:char(6);not null"`
	Email        string    `json:"email" gorm:"type:varchar(50);not null;uniqueIndex;default:''"`
	TwoFactorKey string    `json:"-" gorm:"column:two_factor_key;type:varchar(100);default:''"`
	TwoFactorOn  int8      `json:"two_factor_on" gorm:"column:two_factor_on;type:tinyint;not null;default:0"`
	CreatedAt    time.Time `json:"created" gorm:"column:created;autoCreateTime"`
	UpdatedAt    time.Time `json:"updated" gorm:"column:updated;autoUpdateTime"`
	IsAdmin      int8      `json:"is_admin" gorm:"type:tinyint;not null;default:0"`
	Status       Status    `json:"status" gorm:"type:tinyint;not null;default:1"`
	BaseModel    `json:"-" gorm:"-"`
}

用户model

func (*User) Create

func (user *User) Create() (insertId int, err error)

新增

func (*User) Delete

func (user *User) Delete(id int) (int64, error)

删除

func (*User) Disable

func (user *User) Disable(id int) (int64, error)

禁用

func (*User) EmailExists

func (user *User) EmailExists(email string, uid int) (int64, error)

邮箱地址是否存在

func (*User) Enable

func (user *User) Enable(id int) (int64, error)

激活

func (*User) Find

func (user *User) Find(id int) error

获取用户详情

func (*User) List

func (user *User) List(params CommonMap) ([]User, error)

func (*User) Match

func (user *User) Match(username, password string) bool

验证用户名和密码

func (*User) Total

func (user *User) Total() (int64, error)

func (*User) Update

func (user *User) Update(id int, data CommonMap) (int64, error)

更新

func (*User) UpdatePassword

func (user *User) UpdatePassword(id int, password string) (int64, error)

func (*User) UsernameExists

func (user *User) UsernameExists(username string, uid int) (int64, error)

用户名是否存在

type WebHook

type WebHook struct {
	Url      string `json:"url"`
	Template string `json:"template"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL