models

package
v0.0.0-...-24649a1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HashID *hashids.HashID

Functions

func CreateComment

func CreateComment(post Post, name, email, body string) error

func GetConst

func GetConst(name string) string

Types

type Category

type Category struct {
	ID   int
	Name string
}

type CategoryWithNum

type CategoryWithNum struct {
	Category
	Num int64
}

type Comment

type Comment struct {
	ID        int
	PostID    int
	Name      string
	Email     string
	Body      string
	CreatedAt time.Time

	Post Post
}

type Const

type Const struct {
	ID          int
	Name        string
	Description string
	Value       string
}

type HistoryEducation

type HistoryEducation struct {
	ID        uint `gorm:"primaryKey"`
	CreatedAt time.Time
	UpdatedAt time.Time

	Course      string
	City        string
	Description string
	FromTo      string
	Sort        int
}

func GetAllHistoryEducations

func GetAllHistoryEducations() []HistoryEducation

type HistoryWork

type HistoryWork struct {
	ID        uint `gorm:"primaryKey"`
	CreatedAt time.Time
	UpdatedAt time.Time

	Company     string
	JobTitle    string
	Description string
	FromTo      string
	Sort        int
}

func GetAllHistoryWorks

func GetAllHistoryWorks() []HistoryWork

type Migration

type Migration struct {
	Timestamp string
}

type Post

type Post struct {
	ID         int
	Title      string
	Summary    string
	Body       string
	VisitCount int
	CreatedAt  time.Time

	Comments     []Comment
	CommentCount int64 `gorm:"-:all"` // ignore CommentCount field when write, read and migrate with struct
}

func (*Post) AfterFind

func (p *Post) AfterFind(tx *gorm.DB) (err error)

after find post, set the post's CommentCount attribute

func (Post) DeleteCacheCommentCount

func (post Post) DeleteCacheCommentCount()

delete post's comment count value from redis

func (*Post) GetAllComments

func (post *Post) GetAllComments() (comments []Comment, err error)

func (Post) GetCommentCount

func (post Post) GetCommentCount() (count int64, err error)

get post's comment count from redis or query database and cache it

func (*Post) HashID

func (post *Post) HashID() string

used for post's public url

func (Post) IncreaseVisitCount

func (post Post) IncreaseVisitCount()

add post's visit count

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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