store

package
v0.0.0-...-ba59bca Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserStatusBlocked = 0
	UserStatusNormal  = 1
)

Variables

This section is empty.

Functions

func NewDatabase

func NewDatabase() *mongo.Database

Types

type Config

type Config struct {
	Id         string       `json:"id" bson:"_id"`
	Options    data.Options `json:"options" bson:"options"`
	ModifyTime Time         `json:"modify_time" bson:"modify_time"`
}

type ConfigStore

type ConfigStore interface {
	Find(id string) (data.Options, error)
	Save(id string, opts data.Options) error
}

func NewConfigStore

func NewConfigStore(db *mongo.Database) ConfigStore

type Job

type Job struct {
	Id        primitive.ObjectID `json:"id" bson:"_id"`
	Task      string             `json:"task" bson:"task"`
	Handler   string             `json:"handler" bson:"handler"`
	Scheduler string             `json:"scheduler" bson:"scheduler"`
	Mode      int32              `json:"mode" bson:"mode"` // 0-Auto, 1-Manual
	Args      data.Options       `json:"args" bson:"args"`
	FireTime  Time               `json:"fire_time" bson:"fire_time"`
	Dispatch  struct {
		Status int32  `json:"status" bson:"status"` // 0-Unknown,1-Success,2-Failed
		Time   *Time  `json:"time,omitempty" bson:"time,omitempty"`
		Error  string `json:"error,omitempty" bson:"error,omitempty"`
	} `json:"dispatch" bson:"dispatch"`
	Execute struct {
		Status    int32  `json:"status" bson:"status"` // 0-Unknown,1-Success,2-Failed
		Error     string `json:"error,omitempty" bson:"error,omitempty"`
		StartTime *Time  `json:"start_time,omitempty" bson:"start_time,omitempty"`
		EndTime   *Time  `json:"end_time,omitempty" bson:"end_time,omitempty"`
	} `json:"execute" bson:"execute"`
}

type JobStore

type JobStore interface {
	Find(id string) (*Job, error)
	Search(task string, mode int32, dispatchStatus, executeStatus int32, pageIndex, pageSize int64) (jobs []*Job, total int64, err error)
	Create(job *Job) error
	ModifyDispatch(id string, success bool, error string) error
	ModifyExecute(id string, success bool, error string, start, end time.Time) error
	CreateIndexes(ctx context.Context) error
	Count(ctx context.Context) (int64, error)
}

func NewJobStore

func NewJobStore(db *mongo.Database) JobStore

type LockStore

type LockStore interface {
	Create(key, value string) error
	Delete(key string) error
	CreateIndexes(ctx context.Context) error
}

func NewLockStore

func NewLockStore(db *mongo.Database) LockStore

type Role

type Role struct {
	ID          string   `json:"id" bson:"_id"`
	Name        string   `json:"name" bson:"name"`
	Description string   `json:"desc" bson:"desc"`
	Perms       []string `json:"perms" bson:"perms"`
	CreateTime  Time     `json:"create_time" bson:"create_time"`
	ModifyTime  Time     `json:"modify_time" bson:"modify_time"`
}

type RoleStore

type RoleStore interface {
	Create(r *Role) error
	Modify(role *Role) error
	Find(id string) (*Role, error)
	Search(name string) ([]*Role, error)
	Delete(id string) error
}

func NewRoleStore

func NewRoleStore(db *mongo.Database) RoleStore

type Task

type Task struct {
	Name        string       `json:"name" bson:"_id" valid:"required"`
	Runner      string       `json:"runner" bson:"runner" valid:"required"`
	Handler     string       `json:"handler,omitempty" bson:"handler,omitempty"`
	Args        data.Options `json:"args" bson:"args"`
	Triggers    []string     `json:"triggers" bson:"triggers"`
	Description string       `json:"desc,omitempty" bson:"desc,omitempty"`
	Enabled     bool         `json:"enabled" bson:"enabled"`
	Maintainers []string     `json:"maintainers" bson:"maintainers"`
	Alerts      []string     `json:"alerts" bson:"alerts"`
	ModifyTime  Time         `json:"modify_time" bson:"modify_time"`
}

type TaskStore

type TaskStore interface {
	Find(name string) (*Task, error)
	Delete(name string) error
	Create(t *Task) error
	Modify(t *Task) error
	Search(name, runner string, pageIndex, pageSize int64) (tasks []*Task, total int64, err error)
	GetState() (modify time.Time, count int64, err error)
	FetchAll(enabled bool) ([]*Task, error)
	Count(ctx context.Context) (int64, error)
}

func NewTaskStore

func NewTaskStore(db *mongo.Database) TaskStore

type Time

type Time time.Time

func (Time) Format

func (t Time) Format(layout string) string

func (Time) MarshalBSONValue

func (t Time) MarshalBSONValue() (bsontype.Type, []byte, error)

func (Time) MarshalJSON

func (t Time) MarshalJSON() (b []byte, err error)

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalBSONValue

func (t *Time) UnmarshalBSONValue(bt bsontype.Type, data []byte) error

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

type User

type User struct {
	Id         string    `json:"id" bson:"_id"`
	Name       string    `json:"name" bson:"name" valid:"required"`
	LoginName  string    `json:"login_name" bson:"login_name" valid:"required"`
	Roles      []string  `json:"roles" bson:"roles"`
	Email      string    `json:"email,omitempty" bson:"email" valid:"email"`
	Phone      string    `json:"phone,omitempty" bson:"phone"`
	Wecom      string    `json:"wecom,omitempty" bson:"wecom"`
	Admin      bool      `json:"admin" bson:"admin"`
	Status     int32     `json:"status" bson:"status"` // 0-禁用, 1-正常
	Password   string    `json:"-" bson:"password"`
	Salt       string    `json:"-" bson:"salt" mongo:"create:true,update:false,deep:false"`
	CreateTime time.Time `json:"create_time" bson:"create_time"`
	ModifyTime time.Time `json:"modify_time" bson:"modify_time"`
}

type UserStore

type UserStore interface {
	Create(u *User) error
	Modify(t *User) error
	ModifyProfile(t *User) error
	Find(id string) (u *User, err error)
	FindByName(loginName string) (*User, error)
	Search(name, loginName, filter string, pageIndex, pageSize int64) (users []*User, total int64, err error)
	Fetch(ids []string) (users []*User, err error)
	SetPassword(id string, password, salt string) error
	SetStatus(id string, status int32) error
	Count(ctx context.Context) (int64, error)
	CreateIndexes(ctx context.Context) error
}

func NewUserStore

func NewUserStore(db *mongo.Database) UserStore

Jump to

Keyboard shortcuts

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