Documentation ¶
Overview ¶
Convert Entity to JSON Response Data Structure for API TODO: (refactor) consider to extract this file to a new package
Index ¶
- Constants
- func FindCreateAction[T EntityHasIsEmpty](key string, findAction func() (T, error), createAction func() (T, error)) (T, error)
- func GetTitleByURL(url string) (string, error)
- func QueryDBWithCache[T any](dao *Dao, name string, queryDB func() (T, error)) (T, error)
- func QueryDBWithoutCache[T any](dao *Dao, name string, queryDB func() (T, error)) (T, error)
- type DB
- type Dao
- func (dao *Dao) CacheAction(fn func(cache *DaoCache))
- func (dao *Dao) CacheFlushAll()
- func (dao *Dao) CacheWarmUp()
- func (dao *Dao) CookAllComments(comments []*entity.Comment) []entity.CookedComment
- func (dao *Dao) CookAllNotifies(notifies []entity.Notify) []entity.CookedNotify
- func (dao *Dao) CookAllPages(pages []entity.Page) []entity.CookedPage
- func (dao *Dao) CookComment(c *entity.Comment) entity.CookedComment
- func (dao *Dao) CookCommentForEmail(c *entity.Comment) entity.CookedCommentForEmail
- func (dao *Dao) CookNotify(n *entity.Notify) entity.CookedNotify
- func (dao *Dao) CookPage(p *entity.Page) entity.CookedPage
- func (dao *Dao) CookSite(s *entity.Site) entity.CookedSite
- func (dao *Dao) CookUser(u *entity.User) entity.CookedUser
- func (dao *Dao) CreateAuthIdentity(identity *entity.AuthIdentity) error
- func (dao *Dao) CreateComment(comment *entity.Comment) error
- func (dao *Dao) CreatePage(page *entity.Page) error
- func (dao *Dao) CreateSite(site *entity.Site) error
- func (dao *Dao) CreateUser(user *entity.User) error
- func (dao *Dao) DB() *DB
- func (dao *Dao) DelAuthIdentity(authIdentity *entity.AuthIdentity) error
- func (dao *Dao) DelComment(comment *entity.Comment) error
- func (dao *Dao) DelCommentChildren(parentID uint) error
- func (dao *Dao) DelPage(page *entity.Page) error
- func (dao *Dao) DelSite(site *entity.Site) error
- func (dao *Dao) DelUser(user *entity.User) error
- func (dao *Dao) DropConstraintsIfExist()
- func (dao *Dao) FetchCommentForNotify(n *entity.Notify) entity.Comment
- func (dao *Dao) FetchPageForComment(c *entity.Comment) entity.Page
- func (dao *Dao) FetchPageFromURL(p *entity.Page) error
- func (dao *Dao) FetchSiteForComment(c *entity.Comment) entity.Site
- func (dao *Dao) FetchSiteForPage(p *entity.Page) entity.Site
- func (dao *Dao) FetchUserForComment(c *entity.Comment) entity.User
- func (dao *Dao) FetchUserForNotify(n *entity.Notify) entity.User
- func (dao *Dao) FindAllSites() []entity.Site
- func (dao *Dao) FindAllSitesCooked() []entity.CookedSite
- func (dao *Dao) FindAuthIdentityByRemoteUID(provider string, remoteUID string) entity.AuthIdentity
- func (dao *Dao) FindAuthIdentityByToken(provider string, token string) entity.AuthIdentity
- func (dao *Dao) FindAuthIdentityByUserID(provider string, userID uint) entity.AuthIdentity
- func (dao *Dao) FindComment(id uint, checkers ...func(*entity.Comment) bool) entity.Comment
- func (dao *Dao) FindCommentChildren(parentID uint, checkers ...func(*entity.Comment) bool) []entity.Comment
- func (dao *Dao) FindCommentChildrenShallow(parentID uint, checkers ...func(*entity.Comment) bool) []entity.Comment
- func (dao *Dao) FindCommentRootID(rid uint) uint
- func (dao *Dao) FindCreateNotify(userID uint, commentID uint) entity.Notify
- func (dao *Dao) FindCreatePage(pageKey string, pageTitle string, siteName string) entity.Page
- func (dao *Dao) FindCreateSite(siteName string, siteURLs string) entity.Site
- func (dao *Dao) FindCreateUser(name string, email string, link string) (entity.User, error)
- func (dao *Dao) FindNotify(userID uint, commentID uint) entity.Notify
- func (dao *Dao) FindNotifyForComment(commentID uint, key string) entity.Notify
- func (dao *Dao) FindNotifyParentComment(n *entity.Notify) entity.Comment
- func (dao *Dao) FindPage(key string, siteName string) entity.Page
- func (dao *Dao) FindPageByID(id uint) entity.Page
- func (dao *Dao) FindSite(name string) entity.Site
- func (dao *Dao) FindSiteByID(id uint) entity.Site
- func (dao *Dao) FindUnreadNotifies(userID uint) []entity.Notify
- func (dao *Dao) FindUser(name string, email string) entity.User
- func (dao *Dao) FindUserByID(id uint) entity.User
- func (dao *Dao) FindUserIdsByEmail(email string) []uint
- func (dao *Dao) FindUsersByEmail(email string) []entity.User
- func (dao *Dao) GetAllAdminIDs() []uint
- func (dao *Dao) GetAllAdmins() []entity.User
- func (dao *Dao) GetLinkToReplyByComment(c *entity.Comment, notifyKey ...string) string
- func (dao *Dao) GetPageAccessibleURL(p *entity.Page, s ...*entity.Site) string
- func (dao *Dao) GetReadLinkByNotify(n *entity.Notify) string
- func (dao *Dao) GetTableName(entity any) string
- func (dao *Dao) GetUserAllCommentIDs(userID uint) []uint
- func (dao *Dao) GetVoteNum(targetID uint, voteType string) int
- func (dao *Dao) GetVoteNumUpDown(targetID uint, voteTo string) (int, int)
- func (dao *Dao) IsAdminUser(userID uint) bool
- func (dao *Dao) IsAdminUserByNameEmail(name string, email string) bool
- func (dao *Dao) MergePages()
- func (dao *Dao) MigrateModels()
- func (dao *Dao) MigrateRootID()
- func (dao *Dao) NewNotify(userID uint, commentID uint) entity.Notify
- func (dao *Dao) NewPage(key string, pageTitle string, siteName string) entity.Page
- func (dao *Dao) NewSite(name string, urls string) entity.Site
- func (dao *Dao) NewUser(name string, email string, link string) (entity.User, error)
- func (dao *Dao) NewVote(targetID uint, voteType entity.VoteType, userID uint, ua string, ip string) (entity.Vote, error)
- func (dao *Dao) NotifySetEmailed(n *entity.Notify) error
- func (dao *Dao) NotifySetInitial(n *entity.Notify) error
- func (dao *Dao) NotifySetRead(n *entity.Notify) error
- func (dao *Dao) SetCache(cache *DaoCache)
- func (dao *Dao) SetCommentEmailHashFunc(fn func(string) string)
- func (dao *Dao) UpdateAuthIdentity(authIdentity *entity.AuthIdentity) error
- func (dao *Dao) UpdateComment(comment *entity.Comment) error
- func (dao *Dao) UpdatePage(page *entity.Page) error
- func (dao *Dao) UpdateSite(site *entity.Site) error
- func (dao *Dao) UpdateUser(user *entity.User) error
- func (dao *Dao) UserNotifyMarkAllAsRead(userID uint) error
- func (dao *Dao) UserToCookedForAdmin(u *entity.User) entity.CookedUserForAdmin
- func (dao *Dao) VoteSync()
- type DaoCache
- func (c *DaoCache) ChildCommentCacheDel(comment *entity.Comment)
- func (c *DaoCache) ChildCommentCacheSave(comment *entity.Comment) error
- func (c *DaoCache) CommentCacheDel(comment *entity.Comment)
- func (c *DaoCache) CommentCacheSave(comment *entity.Comment) (err error)
- func (c *DaoCache) PageCacheDel(page *entity.Page)
- func (c *DaoCache) PageCacheSave(page *entity.Page) error
- func (c *DaoCache) SiteCacheDel(site *entity.Site)
- func (c *DaoCache) SiteCacheSave(site *entity.Site) error
- func (c *DaoCache) UserCacheDel(user *entity.User)
- func (c *DaoCache) UserCacheSave(user *entity.User) error
- type EntityHasIsEmpty
Constants ¶
const ( UserByIDKey = "user#id=%d" UserByNameEmailKey = "user#name=%s;email=%s" UserIDByEmailKey = "user_id#email=%s" SiteByIDKey = "site#id=%d" SiteByNameKey = "site#name=%s" PageByIDKey = "page#id=%d" PageByKeySiteNameKey = "page#key=%s;site_name=%s" CommentByIDKey = "comment#id=%d" CommentChildIDsByIDKey = "comment_child_ids#id=%d" NotifyByUserCommentKey = "notify#user_id=%d;comment_id=%d" )
const CommonDateTimeFormat = "2006-01-02 15:04:05"
Variables ¶
This section is empty.
Functions ¶
func FindCreateAction ¶
func FindCreateAction[T EntityHasIsEmpty]( key string, findAction func() (T, error), createAction func() (T, error), ) (T, error)
FindCreateAction is a thread-safe function that attempts to find an entity using the provided findAction function. If the entity does not exist or the result is empty, it will execute the createAction function to create a new entity.
The function ensures that only one goroutine can perform the find or create operation for a given key at a time, using the singleflight mechanism to prevent duplicate operations.
func GetTitleByURL ¶
func QueryDBWithCache ¶
Types ¶
type Dao ¶
type Dao struct {
// contains filtered or unexported fields
}
func (*Dao) CacheAction ¶
func (*Dao) CookAllComments ¶
func (dao *Dao) CookAllComments(comments []*entity.Comment) []entity.CookedComment
func (*Dao) CookAllNotifies ¶
func (dao *Dao) CookAllNotifies(notifies []entity.Notify) []entity.CookedNotify
func (*Dao) CookAllPages ¶
func (dao *Dao) CookAllPages(pages []entity.Page) []entity.CookedPage
func (*Dao) CookComment ¶
func (dao *Dao) CookComment(c *entity.Comment) entity.CookedComment
func (*Dao) CookCommentForEmail ¶
func (dao *Dao) CookCommentForEmail(c *entity.Comment) entity.CookedCommentForEmail
func (*Dao) CookNotify ¶
func (dao *Dao) CookNotify(n *entity.Notify) entity.CookedNotify
func (*Dao) CreateAuthIdentity ¶
func (dao *Dao) CreateAuthIdentity(identity *entity.AuthIdentity) error
func (*Dao) DelAuthIdentity ¶
func (dao *Dao) DelAuthIdentity(authIdentity *entity.AuthIdentity) error
func (*Dao) DropConstraintsIfExist ¶
func (dao *Dao) DropConstraintsIfExist()
Remove all constraints
func (*Dao) FetchCommentForNotify ¶
func (*Dao) FetchPageForComment ¶
func (*Dao) FetchSiteForComment ¶
func (*Dao) FetchUserForComment ¶
func (*Dao) FetchUserForNotify ¶
获取接收通知的用户
func (*Dao) FindAllSites ¶
func (*Dao) FindAllSitesCooked ¶
func (dao *Dao) FindAllSitesCooked() []entity.CookedSite
func (*Dao) FindAuthIdentityByRemoteUID ¶
func (dao *Dao) FindAuthIdentityByRemoteUID(provider string, remoteUID string) entity.AuthIdentity
func (*Dao) FindAuthIdentityByToken ¶
func (dao *Dao) FindAuthIdentityByToken(provider string, token string) entity.AuthIdentity
func (*Dao) FindAuthIdentityByUserID ¶
func (dao *Dao) FindAuthIdentityByUserID(provider string, userID uint) entity.AuthIdentity
func (*Dao) FindComment ¶
func (*Dao) FindCommentChildren ¶
func (*Dao) FindCommentChildrenShallow ¶
func (dao *Dao) FindCommentChildrenShallow(parentID uint, checkers ...func(*entity.Comment) bool) []entity.Comment
(Cached:parent-comments)
func (*Dao) FindCommentRootID ¶
func (*Dao) FindCreateNotify ¶
func (*Dao) FindCreatePage ¶
func (*Dao) FindCreateSite ¶
func (*Dao) FindCreateUser ¶
func (*Dao) FindNotify ¶
#region Notify
func (*Dao) FindNotifyForComment ¶
func (*Dao) FindNotifyParentComment ¶
func (*Dao) FindUserIdsByEmail ¶
查找用户 ID (仅根据 email)
func (*Dao) FindUsersByEmail ¶
查找用户 (仅根据 email)
func (*Dao) GetAllAdminIDs ¶
func (*Dao) GetLinkToReplyByComment ¶
获取评论回复链接
func (*Dao) GetPageAccessibleURL ¶
获取可访问链接
func (*Dao) GetTableName ¶
Get the table name of the entity
func (*Dao) GetUserAllCommentIDs ¶
func (*Dao) GetVoteNum ¶
#region Vote
func (*Dao) GetVoteNumUpDown ¶
func (*Dao) IsAdminUser ¶
func (*Dao) IsAdminUserByNameEmail ¶
func (*Dao) MergePages ¶
func (dao *Dao) MergePages()
func (*Dao) MigrateModels ¶
func (dao *Dao) MigrateModels()
func (*Dao) MigrateRootID ¶
func (dao *Dao) MigrateRootID()
func (*Dao) SetCommentEmailHashFunc ¶
func (*Dao) UpdateAuthIdentity ¶
func (dao *Dao) UpdateAuthIdentity(authIdentity *entity.AuthIdentity) error
func (*Dao) UserNotifyMarkAllAsRead ¶
func (*Dao) UserToCookedForAdmin ¶
func (dao *Dao) UserToCookedForAdmin(u *entity.User) entity.CookedUserForAdmin
type DaoCache ¶
func NewCacheAdaptor ¶
func (*DaoCache) ChildCommentCacheDel ¶
func (*DaoCache) ChildCommentCacheSave ¶
缓存 父ID=>子ID 评论数据
func (*DaoCache) CommentCacheDel ¶
func (*DaoCache) CommentCacheSave ¶
func (*DaoCache) PageCacheDel ¶
func (*DaoCache) SiteCacheDel ¶
func (*DaoCache) UserCacheDel ¶
type EntityHasIsEmpty ¶
type EntityHasIsEmpty interface {
IsEmpty() bool
}