model

package
v0.0.0-...-3268d42 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteUser

func DeleteUser(id uint64) error

DeleteUser deletes the user by the user identifier.

func GetDockerDB

func GetDockerDB() *gorm.DB

func GetSelfDB

func GetSelfDB() *gorm.DB

func InitDockerDB

func InitDockerDB() *gorm.DB

func InitSelfDB

func InitSelfDB() *gorm.DB

used for cli

Types

type BaseModel

type BaseModel struct {
	Id        uint64     `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"-"`
	CreatedAt time.Time  `gorm:"column:createdAt" json:"-"`
	UpdatedAt time.Time  `gorm:"column:updatedAt" json:"-"`
	DeletedAt *time.Time `gorm:"column:deletedAt" sql:"index" json:"-"`
}

type Database

type Database struct {
	Self   *gorm.DB
	Docker *gorm.DB
}
var DB *Database

func (*Database) Close

func (db *Database) Close()

func (*Database) Init

func (db *Database) Init()

type Token

type Token struct {
	Token string `json:"token"`
}

Token represents a JSON web token.

type UserInfo

type UserInfo struct {
	Id        uint64 `json:"id"`
	Username  string `json:"username"`
	SayHello  string `json:"sayHello"`
	Password  string `json:"password"`
	CreatedAt string `json:"createdAt"`
	UpdatedAt string `json:"updatedAt"`
}

type UserList

type UserList struct {
	Lock  *sync.Mutex
	IdMap map[uint64]*UserInfo
}

type UserModel

type UserModel struct {
	BaseModel
	Username string `json:"username" gorm:"column:username;not null" binding:"required" validate:"min=1,max=32"`
	Password string `json:"password" gorm:"column:password;not null" binding:"required" validate:"min=5,max=128"`
}

User represents a registered user.

func GetUser

func GetUser(username string) (*UserModel, error)

GetUser gets an user by the user identifier.

func ListUser

func ListUser(username string, offset, limit int) ([]*UserModel, uint64, error)

ListUser List all users

func (*UserModel) Compare

func (u *UserModel) Compare(pwd string) (err error)

Compare with the plain text password. Returns true if it's the same as the encrypted one (in the `User` struct).

func (*UserModel) Create

func (u *UserModel) Create() error

Create creates a new user account.

func (*UserModel) Encrypt

func (u *UserModel) Encrypt() (err error)

Encrypt the user password.

func (*UserModel) TableName

func (c *UserModel) TableName() string

func (*UserModel) Update

func (u *UserModel) Update() error

Update updates an user account information.

func (*UserModel) Validate

func (u *UserModel) Validate() error

Validate the fields.

Jump to

Keyboard shortcuts

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