handler

package
v1.1.38 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const LOCK_TABLE = "lock_optimistic"
View Source
const STATUS_LOCK = 1
View Source
const STATUS_UNLOCK = 0
View Source
const VERSION_MAG_TABLE = "migrate_version"

Variables

View Source
var CREATE_LOCK_TABLE_SQL = fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS  %s
(
	id        bigint unsigned                         NOT NULL AUTO_INCREMENT,
	lock_name varchar(64) COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '' COMMENT '锁名',
	lock_at datetime DEFAULT NULL COMMENT '锁定时间',
	unlock_at datetime DEFAULT NULL COMMENT '解锁时间',
    lock_host varchar(32) COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '' COMMENT '主机信息',
	timeout bigint unsigned default 0 COMMENT '超时时间,单位:秒',
    status int unsigned DEFAULT 0 COMMENT '锁状态,0:未锁定,1:已锁',

    PRIMARY KEY (id),
    UNIQUE KEY idx_lock (lock_name)
) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT ='乐观锁表'
`, LOCK_TABLE)
View Source
var CREATE_VERSION_TABLE_SQL = fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS  %s
(
    id         bigint unsigned                         NOT NULL AUTO_INCREMENT,
    created_at timestamp                               NOT NULL DEFAULT CURRENT_TIMESTAMP,

	label varchar(20) COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '' COMMENT 'label',
    version   varchar(20) COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '' COMMENT '版本号',
    upgrade_file         varchar(255) COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '' COMMENT '升级文件',
    PRIMARY KEY (id),
    UNIQUE KEY idx_version (label,version)
) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT ='升级表'
`, VERSION_MAG_TABLE)

Functions

This section is empty.

Types

type DbVersionInfo added in v1.1.10

type DbVersionInfo struct {
	Version    string
	SqlContent string
	Comment    string
}

type ILogger

type ILogger interface {
	AddLogger(logger logFunc)
}

type IOptimisticLock

type IOptimisticLock interface {
	Lock(name string) bool
	UnLock(name string) bool
}

func NewOptimisticLock

func NewOptimisticLock(db *sql.DB, timeout int64) (IOptimisticLock, error)

type IVersionMag

type IVersionMag interface {
	Upgrade(version string) error
	UpgradeOne(version string, sqlFile string) error
	Version() (string, error)

	SetLabel(label string)
	Label() string

	ILogger
}

func NewDBVersionMag

func NewDBVersionMag(sqlDir string, db *sql.DB) (IVersionMag, error)

type IVersionMagV2 added in v1.1.10

type IVersionMagV2 interface {
	AppendVersionDir(sqlDir string) error
	AppendVersion(v DbVersionInfo)
	AppendSqlContent(version string, content string)
	AppendEmbedFS(fs embed.FS) error
	AllVersionInfo() []DbVersionInfo

	Upgrade(version string) error
	UpgradeOne(vInfo DbVersionInfo) error
	Version() (string, error)

	SetLabel(label string)
	Label() string

	SetVars(map[string]string)

	ILogger
}

func NewDBVersionMagV2

func NewDBVersionMagV2(db *sql.DB) (IVersionMagV2, error)

type JwtTokenHandler

type JwtTokenHandler struct {
	SecretKey string
}

func NewJwtTokenHandler added in v1.1.8

func NewJwtTokenHandler(secret string) *JwtTokenHandler

func (*JwtTokenHandler) GetToken

func (h *JwtTokenHandler) GetToken(data interface{}) (string, error)

func (*JwtTokenHandler) ParseToken

func (h *JwtTokenHandler) ParseToken(data interface{}, token string) error

type Lock

type Lock struct {
	LockName string
	LockAt   string
	UnLockAt string
	LockHost string
	Timeout  int64
	Status   int
}

func (*Lock) IsLock

func (l *Lock) IsLock() bool

type OptimisticLock

type OptimisticLock struct {
	// contains filtered or unexported fields
}

func (*OptimisticLock) Lock

func (this *OptimisticLock) Lock(name string) bool

func (*OptimisticLock) UnLock

func (this *OptimisticLock) UnLock(name string) bool

type VersionMag

type VersionMag struct {
	// contains filtered or unexported fields
}

func (*VersionMag) AddLogger

func (this *VersionMag) AddLogger(logger logFunc)

func (*VersionMag) Label

func (this *VersionMag) Label() string

func (*VersionMag) SetLabel

func (this *VersionMag) SetLabel(label string)

func (VersionMag) Upgrade

func (this VersionMag) Upgrade(version string) error

升级版本

func (*VersionMag) UpgradeOne

func (this *VersionMag) UpgradeOne(upVersion string, sqlFile string) error

升级一次版本

func (VersionMag) Version

func (this VersionMag) Version() (string, error)

获取当前版本信息

type VersionMagV2

type VersionMagV2 struct {
	// contains filtered or unexported fields
}

func (*VersionMagV2) AddLogger

func (mag *VersionMagV2) AddLogger(logger logFunc)

func (*VersionMagV2) AllVersionInfo added in v1.1.37

func (mag *VersionMagV2) AllVersionInfo() []DbVersionInfo

func (*VersionMagV2) AppendEmbedFS added in v1.1.37

func (mag *VersionMagV2) AppendEmbedFS(fss embed.FS) error

func (*VersionMagV2) AppendSqlContent added in v1.1.10

func (mag *VersionMagV2) AppendSqlContent(version string, content string)

func (*VersionMagV2) AppendVersion added in v1.1.10

func (mag *VersionMagV2) AppendVersion(v DbVersionInfo)

func (*VersionMagV2) AppendVersionDir added in v1.1.10

func (mag *VersionMagV2) AppendVersionDir(sqlDir string) error

func (*VersionMagV2) Label

func (mag *VersionMagV2) Label() string

func (*VersionMagV2) SetLabel

func (mag *VersionMagV2) SetLabel(label string)

func (*VersionMagV2) SetVars added in v1.1.27

func (mag *VersionMagV2) SetVars(vars map[string]string)

func (*VersionMagV2) Upgrade

func (mag *VersionMagV2) Upgrade(version string) error

升级版本

func (*VersionMagV2) UpgradeOne

func (mag *VersionMagV2) UpgradeOne(vInfo DbVersionInfo) error

升级一次版本

func (VersionMagV2) Version

func (mag VersionMagV2) Version() (string, error)

获取当前版本信息

Jump to

Keyboard shortcuts

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