models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2017 License: MIT Imports: 7 Imported by: 6

Documentation

Overview

Package models 为项目所需的模型对象定义.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMemberNoExist 用户不存在.
	ErrMemberNoExist = errors.New("用户不存在")
	// ErrorMemberPasswordError 密码错误.
	ErrorMemberPasswordError = errors.New("用户密码错误")
	// ErrServerAlreadyExist 指定的服务已存在.
	ErrServerAlreadyExist = errors.New("服务已存在")

	// ErrInvalidParameter 参数错误.
	ErrInvalidParameter = errors.New("Invalid parameter")
)

Functions

This section is empty.

Types

type Member

type Member struct {
	MemberId      int       `orm:"pk;auto;unique;column(member_id)"`
	Account       string    `orm:"size(255);column(account)"`
	Password      string    `orm:"size(1000);column(password)"`
	Email         string    `orm:"size(255);column(email);null;default(null)"`
	Phone         string    `orm:"size(255);column(phone);null;default(null)"`
	Avatar        string    `orm:"size(1000);column(avatar)"`
	Role          int       `orm:"column(role);type(int);default(1)"`   //用户角色:0 管理员/1 普通用户
	Status        int       `orm:"column(status);type(int);default(0)"` //用户状态:0 正常/1 禁用
	CreateTime    time.Time `orm:"type(datetime);column(create_time);auto_now_add"`
	CreateAt      int       `orm:"type(int);column(create_at)"`
	LastLoginTime time.Time `orm:"type(datetime);column(last_login_time);null"`
}

Member 会员信息.

func NewMember

func NewMember() *Member

NewMember 获取新的用户信息对象.

func (*Member) Add

func (member *Member) Add() error

Add 添加一个用户.

func (*Member) Delete

func (m *Member) Delete() error

Delete 删除一个用户.

func (*Member) Find

func (m *Member) Find() error

Find 根据用户ID查找用户.

func (*Member) Login

func (m *Member) Login(account string, password string) (*Member, error)

Login 用户登录.

func (*Member) TableEngine

func (m *Member) TableEngine() string

TableEngine 获取数据使用的引擎.

func (*Member) TableName

func (m *Member) TableName() string

TableName 获取对应数据库表名.

func (*Member) Update

func (m *Member) Update(cols ...string) error

Update 更新用户信息.

type Relation

type Relation struct {
	RelationId int       `orm:"pk;auto;unique;column(relation_id)" json:"relation_id"`
	WebHookId  int       `orm:"type(int);column(web_hook_id)" json:"web_hook_id"`
	ServerId   int       `orm:"type(int);column(server_id)" json:"server_id"`
	MemberId   int       `orm:"type(int);column(member_id)" json:"member_id"`
	CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"` //添加时间
}

Relation WebHook和Server之间关系

func NewRelation

func NewRelation() *Relation

Relation 获取新的关系对象

func (*Relation) Delete

func (m *Relation) Delete() error

Delete 删除关系

func (*Relation) DeleteByWhere

func (m *Relation) DeleteByWhere(where string, args ...interface{}) error

DeleteByWhere 删除指定用户的服务和WebHook的关系

func (*Relation) Find

func (m *Relation) Find(id int) error

Find 查找关系

func (*Relation) QueryByWebHookId

func (m *Relation) QueryByWebHookId(webHookId int, memberId int) ([]*ServerRelation, error)

QueryByWebHookId 查找指定用户的服务和WebHook简单关系

func (*Relation) Save

func (m *Relation) Save() error

Save 更新或添加映射关系

func (*Relation) TableEngine

func (m *Relation) TableEngine() string

TableEngine 获取数据使用的引擎

func (*Relation) TableName

func (m *Relation) TableName() string

TableName 获取对应数据库表名

type RelationDetailed

type RelationDetailed struct {
	RelationId     int    `json:"relation_id"`
	MemberId       int    `json:"member_id"`
	WebHookId      int    `json:"web_hook_id" orm:"column(web_hook_id)"`
	RepositoryName string `json:"repository_name"`
	BranchName     string `json:"branch_name"`
	ServerId       int    `json:"server_id"`
	WebHookTag     string `json:"web_hook_tag"`
	Shell          string `json:"shell"`
	WebHookStatus  int    `json:"web_hook_status"`
	Key            string `json:"key"`
	Secure         string `json:"secure"`
	HookType       string `json:"hook_type"` //服务类型

	ServerName   string `json:"server_name"`
	ServerType   string `json:"server_type"`
	IpAddress    string `json:"ip_address"`
	Port         int    `json:"port"`
	Account      string `json:"account"`
	PrivateKey   string `json:"-"`
	ServerTag    string `json:"server_tag"`
	ServerStatus int    `json:"server_status"`
}

RelationDetailed 包含 WebHook 和 Server 信息的关系实体

func FindRelationDetailedByWhere

func FindRelationDetailedByWhere(where string, params ...interface{}) ([]RelationDetailed, error)

FindRelationDetailedByWhere 指定条件查询完整的关系对象

type Scheduler

type Scheduler struct {
	SchedulerId   int       `orm:"pk;auto;unique;column(scheduler_id)" json:"scheduler_id"`
	WebHookId     int       `orm:"type(int);column(web_hook_id)" json:"web_hook_id"`
	ServerId      int       `orm:"type(int);column(server_id)" json:"server_id"`
	RelationId    int       `orm:"type(int);column(relation_id)" json:"relation_id"`
	Status        string    `orm:"column(status);default(wait)" json:"status"`                         //状态:wait 等待执行/executing 执行中/suspend 中断执行/ failure 执行失败/ success 执行成功
	CreateTime    time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"` //添加时间
	StartExecTime time.Time `orm:"type(datetime);column(start_exec_time);null" json:"start_exec_time"` //开始执行时间
	EndExecTime   time.Time `orm:"type(datetime);column(end_exec_time);null" json:"end_exec_time"`     //执行结束时间
	Data          string    `orm:"type(text);column(data)" json:"-"`                                   //推送的数据
	PushUser      string    `orm:"column(push_user);null;size(255)" json:"push_user"`                  //推送用户
	ShaValue      string    `orm:"column(sha_value);null;size(255)" json:"sha_value"`                  //当前请求的sha值
	LogContent    string    `orm:"column(log_content);type(text);" json:"log_content"`
	ExecuteType   int       `orm:"column(execute_type);type(int);default(0)" json:"execute_type"` //执行方式:0 自动触发 / 1 手动执行
}

Scheduler 任务调度器储存表

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler 新建对象

func (*Scheduler) DeleteByWhere

func (m *Scheduler) DeleteByWhere(where string, args ...interface{}) error

DeleteByWhere 根据条件删除

func (*Scheduler) Find

func (m *Scheduler) Find() error

Find 根据ID查找对象

func (*Scheduler) InsertMulti

func (m *Scheduler) InsertMulti(schedulers []Scheduler) (int64, error)

InsertMulti 批量插入对象

func (*Scheduler) QuerySchedulerByState

func (m *Scheduler) QuerySchedulerByState(state ...string) ([]Scheduler, error)

QuerySchedulerByState 根据状态查询

func (*Scheduler) Save

func (m *Scheduler) Save() error

Save 更新或插入

func (*Scheduler) TableEngine

func (m *Scheduler) TableEngine() string

TableEngine 获取数据使用的引擎

func (*Scheduler) TableName

func (m *Scheduler) TableName() string

TableName 获取对应数据库表名

func (*Scheduler) ToWebScheduler

func (m *Scheduler) ToWebScheduler() WebScheduler

ToWebScheduler 转换为前端可用的优化信息对象

type Server

type Server struct {
	ServerId   int       `orm:"pk;auto;unique;column(server_id)" json:"server_id"`
	Name       string    `orm:"size(255);column(name)" json:"name"`
	Type       string    `orm:"size(255);column(type);default(ssh)" json:"type"`
	IpAddress  string    `orm:"size(255);column(ip_address)" json:"ip_address"`
	Port       int       `orm:"type(int);column(port)" json:"port"`
	Account    string    `orm:"size(255);column(account)" json:"account"`
	PrivateKey string    `orm:"type(text);column(private_key)" json:"private_key"`
	Tag        string    `orm:"size(1000);column(tag)" json:"tag"`
	Status     int       `orm:"type(int);column(status);default(0)" json:"status"`
	CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
	CreateAt   int       `orm:"type(int);column(create_at)" json:"-"`
}

服务器对象

func NewServer

func NewServer() *Server

新建服务器对象

func (*Server) Delete

func (m *Server) Delete() error

删除

func (*Server) Find

func (m *Server) Find() error

根据ID查找对象

func (*Server) QueryServerByServerId

func (m *Server) QueryServerByServerId(serverIds []int, memberId ...int) ([]*Server, error)

根据server_id和用户id查询服务器信息列表

func (*Server) Save

func (m *Server) Save() error

创建或更新

func (*Server) Search

func (m *Server) Search(keyword string, memberId int, excludeServerId ...int) ([]Server, error)

搜索指定用户的服务器

func (*Server) TableEngine

func (m *Server) TableEngine() string

获取数据使用的引擎

func (*Server) TableName

func (m *Server) TableName() string

获取对应数据库表名

type ServerRelation

type ServerRelation struct {
	ServerId   int
	RelationId int
	WebHookId  int
	MemberId   int
	Status     int
	Name       string
	IpAddress  string
	Port       int
	Type       string
	CreateTime time.Time
	CreateAt   int
}

ServerRelation 服务与WebHook简单关系

type WebHook

type WebHook struct {
	WebHookId      int       `orm:"pk;auto;unique;column(web_hook_id)" json:"web_hook_id"`
	RepositoryName string    `orm:"size(255);column(repo_name)" json:"repository_name"`
	BranchName     string    `orm:"size(255);column(branch_name)" json:"branch_name"`
	Tag            string    `orm:"size(1000);column(tag)" json:"tag"`
	Shell          string    `orm:"size(1000);column(shell)" json:"shell"`
	Status         int       `orm:"type(int);column(status);default(0)" json:"status"`
	Key            string    `orm:"size(255);column(key);unique" json:"key"`
	Secure         string    `orm:"size(255);column(secure)" json:"secure"`
	LastExecTime   time.Time `orm:"type(datetime);column(last_exec_time);null" json:"last_exec_time"`
	CreateTime     time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
	HookType       string    `orm:"column(hook_type);size(50)" json:"hook_type"`
	CreateAt       int       `orm:"type(int);column(create_at)"`
}

WebHook对象

func NewWebHook

func NewWebHook() *WebHook

新建 WebHook 对象

func (*WebHook) Delete

func (m *WebHook) Delete() error

删除一条

func (*WebHook) DeleteMulti

func (m *WebHook) DeleteMulti(id ...int) error

批量删除

func (*WebHook) Find

func (m *WebHook) Find() error

查找

func (*WebHook) FindByKey

func (m *WebHook) FindByKey(key string) error

根据Key查找

func (*WebHook) Save

func (m *WebHook) Save() error

添加或更新

func (*WebHook) TableEngine

func (m *WebHook) TableEngine() string

获取数据使用的引擎

func (*WebHook) TableName

func (m *WebHook) TableName() string

获取对应数据库表名

type WebScheduler

type WebScheduler struct {
	Scheduler
	Slogan    string `json:"slogan"`
	Consuming string `json:"consuming"`
}

WebScheduler 前端使用的结构体

Jump to

Keyboard shortcuts

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