model

package
v0.0.0-...-476b199 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CacheFindGroup = new(singleflight.Group)
)

Functions

func CacheFlushAll

func CacheFlushAll()

清空缓存

func CacheWarmUp

func CacheWarmUp()

缓存预热

func ChildCommentCacheDel

func ChildCommentCacheDel(parentID uint)

func ChildCommentCacheSave

func ChildCommentCacheSave(parentID uint, childID uint)

缓存 父ID=>子ID 评论数据

func CommentCacheDel

func CommentCacheDel(comment *Comment)

func CommentCacheSave

func CommentCacheSave(comment *Comment) error

func ContainsComment

func ContainsComment(comments []Comment, targetID uint) bool

func ContainsCookedComment

func ContainsCookedComment(comments []CookedComment, targetID uint) bool

func CreateComment

func CreateComment(comment *Comment) error

func CreatePage

func CreatePage(page *Page) error

func CreateSite

func CreateSite(site *Site) error

func CreateUser

func CreateUser(user *User) error

func DB

func DB() *gorm.DB

func DelCache

func DelCache(name string) error

func DelComment

func DelComment(comment *Comment) error

func DelCommentChildren

func DelCommentChildren(parentID uint) error

删除所有子评论

func DelPage

func DelPage(page *Page) error

func DelSite

func DelSite(site *Site) error

func DelUser

func DelUser(user *User) error

func FindAndStoreCache

func FindAndStoreCache(name string, dest interface{}, queryDBResult func() interface{}) error

func FindCache

func FindCache(name string, dest interface{}) error

func FindUserIdsByEmail

func FindUserIdsByEmail(email string) []uint

查找用户 ID (仅根据 email)

func GetAllAdminIDs

func GetAllAdminIDs() []uint

func GetTitleByURL

func GetTitleByURL(url string) (string, error)

func GetUserAllCommentIDs

func GetUserAllCommentIDs(userID uint) []uint

func GetVoteNum

func GetVoteNum(targetID uint, voteType string) int

#region Vote

func GetVoteNumUpDown

func GetVoteNumUpDown(targetID uint, voteTo string) (int, int)

func IsAdminUser

func IsAdminUser(userID uint) bool

func IsAdminUserByNameEmail

func IsAdminUserByNameEmail(name string, email string) bool

func MigrateModels

func MigrateModels()

func PageCacheDel

func PageCacheDel(page *Page)

func PageCacheSave

func PageCacheSave(page *Page) error

func SetDB

func SetDB(db *gorm.DB)

func SiteCacheDel

func SiteCacheDel(site *Site)

func SiteCacheSave

func SiteCacheSave(site *Site) error

func StoreCache

func StoreCache(name string, source interface{}) error

func SyncFromConf

func SyncFromConf()

func UpdateComment

func UpdateComment(comment *Comment) error

更新评论

func UpdatePage

func UpdatePage(page *Page) error

func UpdateSite

func UpdateSite(site *Site) error

func UpdateUser

func UpdateUser(user *User) error

func UserCacheDel

func UserCacheDel(user *User)

func UserCacheSave

func UserCacheSave(user *User) error

func UserNotifyMarkAllAsRead

func UserNotifyMarkAllAsRead(userID uint) error

Types

type Artran

type Artran struct {
	ID  string `json:"id"`
	Rid string `json:"rid"`

	Content string `json:"content"`

	UA          string `json:"ua"`
	IP          string `json:"ip"`
	IsCollapsed string `json:"is_collapsed"` // bool => string "true" or "false"
	IsPending   string `json:"is_pending"`   // bool
	IsPinned    string `json:"is_pinned"`    // bool

	// vote
	VoteUp   string `json:"vote_up"`
	VoteDown string `json:"vote_down"`

	// date
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`

	// user
	Nick       string `json:"nick"`
	Email      string `json:"email"`
	Link       string `json:"link"`
	BadgeName  string `json:"badge_name"`
	BadgeColor string `json:"badge_color"`

	// page
	PageKey       string `json:"page_key"`
	PageTitle     string `json:"page_title"`
	PageAdminOnly string `json:"page_admin_only"` // bool

	// site
	SiteName string `json:"site_name"`
	SiteUrls string `json:"site_urls"`
}

数据行囊 (n 个 Artran 组成一个 Artrans) Fields All String type (FAS)

type Comment

type Comment struct {
	gorm.Model

	Content string

	PageKey  string `gorm:"index;size:255"`
	SiteName string `gorm:"index;size:255"`

	UserID uint `gorm:"index"`
	UA     string
	IP     string

	Rid uint `gorm:"index"` // 父评论 ID

	IsCollapsed bool `gorm:"default:false"` // 折叠
	IsPending   bool `gorm:"default:false"` // 待审
	IsPinned    bool `gorm:"default:false"` // 置顶

	VoteUp   int
	VoteDown int
	// contains filtered or unexported fields
}

func FindComment

func FindComment(id uint, checkers ...func(*Comment) bool) Comment

func FindCommentChildren

func FindCommentChildren(parentID uint, checkers ...func(*Comment) bool) []Comment

func FindCommentChildrenShallow

func FindCommentChildrenShallow(parentID uint, checkers ...func(*Comment) bool) []Comment

(Cached:parent-comments)

func (*Comment) FetchPage

func (c *Comment) FetchPage() Page

func (*Comment) FetchSite

func (c *Comment) FetchSite() Site

func (*Comment) FetchUser

func (c *Comment) FetchUser() User

func (*Comment) GetLinkToReply

func (c *Comment) GetLinkToReply(notifyKey ...string) string

获取评论回复链接

func (Comment) IsAllowReply

func (c Comment) IsAllowReply() bool

func (Comment) IsEmpty

func (c Comment) IsEmpty() bool

func (*Comment) ToArtran

func (c *Comment) ToArtran() Artran

func (*Comment) ToCooked

func (c *Comment) ToCooked() CookedComment

func (*Comment) ToCookedForEmail

func (c *Comment) ToCookedForEmail() CookedCommentForEmail

type CookedComment

type CookedComment struct {
	ID             uint   `json:"id"`
	Content        string `json:"content"`
	ContentMarked  string `json:"content_marked"`
	UserID         uint   `json:"user_id"`
	Nick           string `json:"nick"`
	EmailEncrypted string `json:"email_encrypted"`
	Link           string `json:"link"`
	UA             string `json:"ua"`
	Date           string `json:"date"`
	IsCollapsed    bool   `json:"is_collapsed"`
	IsPending      bool   `json:"is_pending"`
	IsPinned       bool   `json:"is_pinned"`
	IsAllowReply   bool   `json:"is_allow_reply"`
	Rid            uint   `json:"rid"`
	BadgeName      string `json:"badge_name"`
	BadgeColor     string `json:"badge_color"`
	Visible        bool   `json:"visible"`
	VoteUp         int    `json:"vote_up"`
	VoteDown       int    `json:"vote_down"`
	PageKey        string `json:"page_key"`
	PageURL        string `json:"page_url"`
	SiteName       string `json:"site_name"`
}

func CookAllComments

func CookAllComments(comments []Comment) []CookedComment

type CookedCommentForEmail

type CookedCommentForEmail struct {
	CookedComment
	Content    string     `json:"content"`
	ContentRaw string     `json:"content_raw"`
	Nick       string     `json:"nick"`
	Email      string     `json:"email"`
	IP         string     `json:"ip"`
	Datetime   string     `json:"datetime"`
	Date       string     `json:"date"`
	Time       string     `json:"time"`
	PageKey    string     `json:"page_key"`
	PageTitle  string     `json:"page_title"`
	Page       CookedPage `json:"page"`
	SiteName   string     `json:"site_name"`
	Site       CookedSite `json:"site"`
}

type CookedNotify

type CookedNotify struct {
	ID        uint   `json:"id"`
	UserID    uint   `json:"user_id"`
	CommentID uint   `json:"comment_id"`
	IsRead    bool   `json:"is_read"`
	IsEmailed bool   `json:"is_emailed"`
	ReadLink  string `json:"read_link"`
}

func FindUnreadNotifies

func FindUnreadNotifies(userID uint) []CookedNotify

type CookedPage

type CookedPage struct {
	ID        uint   `json:"id"`
	AdminOnly bool   `json:"admin_only"`
	Key       string `json:"key"`
	URL       string `json:"url"`
	Title     string `json:"title"`
	SiteName  string `json:"site_name"`
	VoteUp    int    `json:"vote_up"`
	VoteDown  int    `json:"vote_down"`
	PV        int    `json:"pv"`
}

func CookAllPages

func CookAllPages(pages []Page) []CookedPage

type CookedSite

type CookedSite struct {
	ID       uint     `json:"id"`
	Name     string   `json:"name"`
	Urls     []string `json:"urls"`
	UrlsRaw  string   `json:"urls_raw"`
	FirstUrl string   `json:"first_url"`
}

func FindAllSitesCooked

func FindAllSitesCooked() []CookedSite

type CookedUser

type CookedUser struct {
	ID           uint     `json:"id"`
	Name         string   `json:"name"`
	Email        string   `json:"email"`
	Link         string   `json:"link"`
	BadgeName    string   `json:"badge_name"`
	BadgeColor   string   `json:"badge_color"`
	IsAdmin      bool     `json:"is_admin"`
	SiteNames    []string `json:"site_names"`
	SiteNamesRaw string   `json:"site_names_raw"`
	ReceiveEmail bool     `json:"receive_email"`
}

type CookedUserForAdmin

type CookedUserForAdmin struct {
	CookedUser
	LastIP       string `json:"last_ip"`
	LastUA       string `json:"last_ua"`
	IsInConf     bool   `json:"is_in_conf"`
	CommentCount int64  `json:"comment_count"`
}

type Notify

type Notify struct {
	gorm.Model

	UserID    uint `gorm:"index"` // 通知对象 (接收通知的用户 ID)
	CommentID uint `gorm:"index"` // 待查看的评论

	IsRead    bool
	ReadAt    *time.Time
	IsEmailed bool
	EmailAt   *time.Time

	Key string `gorm:"index;size:255"`
	// contains filtered or unexported fields
}

func FindCreateNotify

func FindCreateNotify(userID uint, lookCommentID uint) Notify

func FindNotify

func FindNotify(userID uint, commentID uint) Notify

#region Notify

func FindNotifyByKey

func FindNotifyByKey(key string) Notify

func NewNotify

func NewNotify(userID uint, commentID uint) Notify

func (*Notify) FetchComment

func (n *Notify) FetchComment() Comment

func (*Notify) FetchUser

func (n *Notify) FetchUser() User

获取接收通知的用户

func (*Notify) GenerateKey

func (n *Notify) GenerateKey()

操作时的验证密钥(判断是否本人操作)

func (*Notify) GetParentComment

func (n *Notify) GetParentComment() Comment
func (n *Notify) GetReadLink() string

func (Notify) IsEmpty

func (n Notify) IsEmpty() bool

func (*Notify) SetComment

func (n *Notify) SetComment(comment Comment)

func (*Notify) SetEmailed

func (n *Notify) SetEmailed() error

func (*Notify) SetInitial

func (n *Notify) SetInitial() error

func (*Notify) SetRead

func (n *Notify) SetRead() error

func (*Notify) ToCooked

func (n *Notify) ToCooked() CookedNotify

type Page

type Page struct {
	gorm.Model
	Key       string `gorm:"index;size:255"` // 页面 Key(一般为不含 hash/query 的完整 url)
	Title     string
	AdminOnly bool

	SiteName string `gorm:"index;size:255"`

	VoteUp   int
	VoteDown int

	PV int
	// contains filtered or unexported fields
}

func FindCreatePage

func FindCreatePage(pageKey string, pageTitle string, siteName string) Page

func FindPage

func FindPage(key string, siteName string) Page

func FindPageByID

func FindPageByID(id uint) Page

func NewPage

func NewPage(key string, pageTitle string, siteName string) Page

func (*Page) FetchSite

func (p *Page) FetchSite() Site

func (*Page) FetchURL

func (p *Page) FetchURL() error

func (*Page) GetAccessibleURL

func (p *Page) GetAccessibleURL() string

获取可访问链接

func (Page) IsEmpty

func (p Page) IsEmpty() bool

func (Page) ToCooked

func (p Page) ToCooked() CookedPage

type Site

type Site struct {
	gorm.Model
	Name string `gorm:"uniqueIndex;size:255"`
	Urls string
}

func FindCreateSite

func FindCreateSite(siteName string) Site

func FindSite

func FindSite(name string) Site

func FindSiteByID

func FindSiteByID(id uint) Site

func NewSite

func NewSite(name string, urls string) Site

func (Site) IsEmpty

func (s Site) IsEmpty() bool

func (Site) ToCooked

func (s Site) ToCooked() CookedSite

type User

type User struct {
	gorm.Model
	Name         string `gorm:"index;size:255"`
	Email        string `gorm:"index;size:255"`
	Link         string
	Password     string
	BadgeName    string
	BadgeColor   string
	LastIP       string
	LastUA       string
	IsAdmin      bool
	SiteNames    string
	ReceiveEmail bool `gorm:"default:true"`

	// 配置文件中添加的
	IsInConf bool
}

func FindCreateUser

func FindCreateUser(name string, email string, link string) User

func FindUser

func FindUser(name string, email string) User

查找用户 (精确查找 name & email)

func FindUserByID

func FindUserByID(id uint) User

查找用户 (通过 ID)

func FindUsersByEmail

func FindUsersByEmail(email string) []User

查找用户 (仅根据 email)

func GetAllAdmins

func GetAllAdmins() []User

func NewUser

func NewUser(name string, email string, link string) User

func (User) IsEmpty

func (u User) IsEmpty() bool

func (*User) SetPasswordEncrypt

func (u *User) SetPasswordEncrypt(password string) (err error)

func (User) ToCooked

func (u User) ToCooked() CookedUser

func (User) ToCookedForAdmin

func (u User) ToCookedForAdmin() CookedUserForAdmin

type Vote

type Vote struct {
	gorm.Model

	TargetID uint     `gorm:"index"` // 投票对象
	Type     VoteType `gorm:"index"`

	UserID uint `gorm:"index"` // 投票者
	UA     string
	IP     string
}

func NewVote

func NewVote(targetID uint, voteType VoteType, userID uint, ua string, ip string) (Vote, error)

func (*Vote) IsEmpty

func (v *Vote) IsEmpty() bool

func (*Vote) IsUp

func (v *Vote) IsUp() bool

type VoteType

type VoteType string
const (
	VoteTypeCommentUp   VoteType = "comment_up"
	VoteTypeCommentDown VoteType = "comment_down"
	VoteTypePageUp      VoteType = "page_up"
	VoteTypePageDown    VoteType = "page_down"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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