model

package
v0.0.0-...-3a80bc8 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DevelopmentMode 开发模式
	DevelopmentMode = "development"

	// TestMode 测试模式
	TestMode = "test"

	// ProductionMode 产品模式
	ProductionMode = "production"
)

Variables

View Source
var DB *gorm.DB

Functions

func GetArticleCountByCateId

func GetArticleCountByCateId(cateId uint64) uint64

func GetArticleCountByUserCateId

func GetArticleCountByUserCateId(userId uint64, cateId uint64) uint64

func GetArticleCountByUserId

func GetArticleCountByUserId(userID uint64) uint64

func GetArticleJson

func GetArticleJson(article *Article, cate *Category) string

func GetArticleJsonData

func GetArticleJsonData(perPageInt int, offset int) []interface{}

func GetArtileCount

func GetArtileCount() uint64

func GetCateCountByUserId

func GetCateCountByUserId(userID uint64) uint64

func GetPageCountByUserId

func GetPageCountByUserId(userID uint64) uint64

func InitDB

func InitDB() (*gorm.DB, error)

Types

type Article

type Article struct {
	BaseModel
	Title        string   `json:"title"`
	Desc         string   `json:"desc"`
	Content      string   `json:"content"`
	UserID       uint64   `json:"userId"`
	ViewCount    uint64   `json:"viewCount"`
	CommentCount uint64   `json:"commentCount"`
	CategoryID   uint64   `json:"categoryId"`
	User         User     `gorm:"ForeignKey:ID" json:"user"`
	Category     Category `gorm:"ForeignKey:ID" json:"category"`
	IsPublished  bool
}

Table Article

func GetArticleById

func GetArticleById(id string) (*Article, error)

func GetArticleQuerysByUserId

func GetArticleQuerysByUserId(userID uint64) ([]*Article, error)

func GetRecentArticleQuerys

func GetRecentArticleQuerys() ([]*Article, error)

func (*Article) Delete

func (article *Article) Delete() error

Delete Article

func (*Article) Insert

func (article *Article) Insert() error

Post

func (*Article) Update

func (article *Article) Update() error

Update Article

func (*Article) UpdateView

func (article *Article) UpdateView() error

type ArticleArch

type ArticleArch struct {
	Year      int        `json:"year"`
	Month     string     `json:"month"`
	YearMonth string     `json:"yearMonth"`
	Articles  []*Article `json:"articles"`
}

Article Archive

func GetArticleArchiveQuerys

func GetArticleArchiveQuerys() ([]*ArticleArch, error)

type ArticleCate

type ArticleCate struct {
	CateID    uint64 `json:"cateId"`
	CateCount uint64 `json:"cateCount"`
	CateName  string `json:"cateName"`
}

Article Category

func GetArticleCategoryQuerys

func GetArticleCategoryQuerys() ([]*ArticleCate, error)

type ArticleCateInfo

type ArticleCateInfo struct {
	ID          uint64 `gorm:"primary_key"`
	Title       string `json:"title"`
	Name        string `json:"name"`
	IsPublished bool
	Count       uint64 `json:"count"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Article Category Info

func AdminGetArticleByCategory

func AdminGetArticleByCategory(userId uint64, cateId uint64) ([]*ArticleCateInfo, error)

type ArticleData

type ArticleData struct {
	Title        string `json:"title"`
	ReadCount    uint64 `json:"readCount"`
	ArticleID    uint64 `json:"articleID"`
	CommentCount uint64 `json:"commentCount"`
	Desc         string `json:"desc"`
	Category     string `json:"category"`
	CategoryID   uint64 `json:"categoryID"`
	CreateTime   string `json:"createTime"`
}

ArticleData

func GetArticleArchiveQuerysByTime

func GetArticleArchiveQuerysByTime(archTime string) ([]*ArticleData, error)

func GetArticleQuerysByCateId

func GetArticleQuerysByCateId(cateId uint64) ([]*ArticleData, error)

func GetArticlesByKeyword

func GetArticlesByKeyword(keyword string) ([]*ArticleData, error)

type BaseModel

type BaseModel struct {
	ID        uint64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Base Model

type Category

type Category struct {
	BaseModel
	Name  string `json:"name"`
	Count uint64 `json:"count"`
}

Table Category

func GetCategoryById

func GetCategoryById(cateId uint64) (*Category, error)

Get Category By Id

func GetCategoryByName

func GetCategoryByName(cateName string) (*Category, error)

Get Category by name

func GetCategoryQuerys

func GetCategoryQuerys() ([]*Category, error)

func GetCategoryQuerysByUserId

func GetCategoryQuerysByUserId(userId uint64) ([]*Category, error)

func (*Category) Insert

func (cate *Category) Insert() error

Insert Category

type Link struct {
	BaseModel
	Name   string `json:"name"`        //名称
	Url    string `json:"url"`         //地址
	Sort   int    `json:"default:'0'"` //排序
	View   int    `json:"view"`        //访问次数
	UserID uint64 `json:"userId"`
	User   User   `gorm:"ForeignKey:ID" json:"user"`
}

Table link

func GetLinkQuerysByUserID

func GetLinkQuerysByUserID(userID uint64) ([]*Link, error)

Get Link Querys By UserID

func (*Link) Delete

func (link *Link) Delete() error

Delete Link

func (*Link) Insert

func (link *Link) Insert() error

Insert Link

func (*Link) Update

func (link *Link) Update() error

Update Link

type Page

type Page struct {
	BaseModel
	Title       string `json:"title"`
	Content     string `json:"content"`
	View        int    `json:"view"`
	UserID      uint64 `json:"userId"`
	User        User   `gorm:"ForeignKey:ID" json:"user"`
	IsPublished bool
}

Table Page

func GetPageById

func GetPageById(id string) (*Page, error)

func GetPageQuerysByUserId

func GetPageQuerysByUserId(userID uint64) ([]*Page, error)

func (*Page) Delete

func (page *Page) Delete() error

func (*Page) Insert

func (page *Page) Insert() error

Insert Page

func (*Page) Update

func (page *Page) Update() error

type User

type User struct {
	BaseModel
	RealName    string `json:"realName"`                  //真实姓名
	UserName    string `json:"userName"`                  //昵称
	Email       string `gorm:"unique_index;default:null"` //邮箱
	Telephone   string `gorm:"unique_index;default:null"` //手机号码
	Password    string `gorm:"default:null"`              //密码
	VerifyState string `gorm:"default:'0'"`               //邮箱验证状态
	AvatarUrl   string `json:"avatarUrl"`                 //头像链接
	IsAdmin     bool   //是否是管理员
	LockState   bool   `gorm:"default:'0'"` //锁定状态
}

User Table

func GetUserById

func GetUserById(userId uint64) (*User, error)

Get User

func GetUserQuerys

func GetUserQuerys() ([]*User, error)

Get User Querys

func (User) CheckPassword

func (user User) CheckPassword(password string) bool

CheclPassword 验证密码是否正确

func (User) EncryptPassword

func (user User) EncryptPassword(password, salt string) (hash string)

EncryptPassword 给密码加密

func (*User) Insert

func (user *User) Insert() error

User Insert

func (*User) Lock

func (user *User) Lock() error

Lock User 锁定用户

func (User) Salt

func (user User) Salt() string

Salt 每个用户都有一个不同的盐

func (*User) UpdateImage

func (user *User) UpdateImage() error

func (*User) UpdateUserInfo

func (user *User) UpdateUserInfo() error

func (*User) UpdateUserPwd

func (user *User) UpdateUserPwd() error

Jump to

Keyboard shortcuts

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