model

package
v0.0.0-...-1d8ee1f Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDockerDB

func GetDockerDB() *gorm.DB

GetDockerDB 获取docker数据库

func GetSelfDB

func GetSelfDB() *gorm.DB

GetSelfDB 获取DB

func InitDockerDB

func InitDockerDB() *gorm.DB

InitDockerDB 初始化docker数据库

func InitSelfDB

func InitSelfDB() *gorm.DB

InitSelfDB 用于命令行

Types

type ArchivePosts

type ArchivePosts struct {
	Year  string
	Posts []PostModel
}

type BaseModel

type BaseModel struct {
	ID        uint64     `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"-"`
	CreatedAt time.Time  `gorm:"column:created_at" json:"-"`
	UpdatedAt time.Time  `gorm:"column:updated_at" json:"-"`
	DeletedAt *time.Time `gorm:"column:deleted_at" sql:"index" json:"-"`
}

BaseModel 实体基础类

type Database

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

Database 数据库

var DB *Database

DB .

func (*Database) AutoMigrate

func (db *Database) AutoMigrate()

AutoMigrate 初始化表结构

func (*Database) Close

func (db *Database) Close()

Close 关闭数据库

func (*Database) Init

func (db *Database) Init()

Init 初始化

type LiClass

type LiClass struct {
	Class []string
	Href  string
	Text  string
	TOCs  []TOC
}

type PostModel

type PostModel struct {
	BaseModel
	CanComment int           `gorm:"column:can_comment;type:tinyint" json:"can_comment"`
	Status     int           `gorm:"column:status;type:smallint" json:"status"`
	Title      string        `gorm:"column:title;type:varchar(100)" json:"title"`
	AuthorID   int           `gorm:"column:author_id" json:"author_id"`
	Slug       string        `gorm:"column:slug;type:varchar(100)" json:"slug"`
	Summary    string        `gorm:"column:summary;type:varchar(255)" json:"summary"`
	Typ        int           `gorm:"column:type;type:int" json:"type"`
	PageView   int           `gorm:"column:pageview;type:int" json:"pageview"`
	Content    string        `gorm:"column:content;type:text" json:"content"`
	Name       string        `gorm:"-"`
	Tags       []Tag         `gorm:"-"`
	Avatar     string        `gorm:"-"`
	HTML       template.HTML `gorm:"-"`
	TOC        template.HTML `gorm:"-"`
}

PostModel 文章表

func (*PostModel) TableName

func (p *PostModel) TableName() string

TableName 修改表名

func (*PostModel) TagStr

func (p *PostModel) TagStr() string

TagStr 返回标签

type PostTag

type PostTag struct {
	BaseModel
	PostID int `gorm:"column:post_id"`
	TagID  int `gorm:"column:tag_id"`
}

func (*PostTag) TableName

func (pt *PostTag) TableName() string

TableName 默认表名

type TOC

type TOC struct {
	OlClass string
	LiClass []LiClass
}

type Tag

type Tag struct {
	BaseModel
	Name  string `gorm:"column:name"`
	Count int    `gorm:"-"`
}

func (*Tag) TableName

func (t *Tag) TableName() string

TableName 表名

type Token

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

Token .

type UserModel

type UserModel struct {
	BaseModel
	Username string `json:"name" gorm:"column:name;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"`
	Email    string `json:"email" gorm:"column:email;not null"`
	Avatar   string `json:"avatar" gorm:"column:avatar"`
	Active   bool   `json:"active" gorm:"column:active"`
}

UserModel 用户实体

func GetUser

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

GetUser 通过用户名获取用户实体

func (*UserModel) Create

func (u *UserModel) Create() error

Create 创建用户

func (*UserModel) Encrypt

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

Encrypt 加密密码

func (*UserModel) TableName

func (u *UserModel) TableName() string

TableName 表名

func (*UserModel) Validate

func (u *UserModel) Validate() error

Validate 校验数据

Jump to

Keyboard shortcuts

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