Documentation ¶
Index ¶
- Constants
- Variables
- func AddNewArticleList(cid uint64, rankItems []ArticleRankItem)
- func ContentFmt(input string) string
- func ContentRich(input string) string
- func CreateActionRecord(gormDB *gorm.DB, userID uint64, postData string) error
- func FlarumCreateCurrentUser(user User) flarum.Resource
- func FlarumCreateDiscussion(topic Topic) flarum.Resource
- func FlarumCreateForumInfo(user *User, appConf AppConf, siteInfo SiteInfo, tags []flarum.Resource) flarum.Resource
- func FlarumCreateGroup() flarum.Resource
- func FlarumCreateLocale(coreData *flarum.CoreData, locale string)
- func FlarumCreatePost(comment Comment, currentUser *User) flarum.Resource
- func FlarumCreatePostRelations(postArr []flarum.Resource, comments []uint64) flarum.IRelation
- func FlarumCreateTag(cat Tag) flarum.Resource
- func FlarumCreateTagRelations(tagArr []flarum.Resource) flarum.IRelation
- func FlarumCreateUser(user User) flarum.Resource
- func FlarumCreateUserLikeRelations(userList []uint64) flarum.RelationArray
- func GetArticleCntFromRedisDB(redisDB *redis.Client, aid uint64) uint64
- func GetAvatarByID(gormDB *gorm.DB, redisDB *redis.Client, uid uint64) string
- func GetCIDArticleMax(cid uint64) uint64
- func GetDays(redisDB *redis.Client) uint64
- func GetTopicListByPageNum(cid uint64, page uint64, limit uint64) []uint64
- func GetUserNameByID(gormDB *gorm.DB, redisDB *redis.Client, uid uint64) string
- func MentionToHTML(content string) string
- func NewCaptcha(path string) string
- func PreProcessUserMention(gormDB *gorm.DB, redisDB *redis.Client, tz int, userComment string) string
- func RankMapInit(gormDB *gorm.DB, redisDB *redis.Client)
- func SaveImage(path, id string)
- func SetCaptchaUseRedisStore(redisDB *redis.Client)
- func TimelyResort()
- type ActionRecord
- type AppConf
- type ArticleFeedListItem
- type ArticleLi
- type ArticleListItem
- type ArticleMini
- type ArticlePageInfo
- type ArticleRankItem
- type ArticleRelative
- type ArticleTag
- type CategoryRankData
- type Comment
- func SQLCommentByID(gormDB *gorm.DB, redisDB *redis.Client, cid uint64, tz int) (Comment, error)
- func SQLCommentListByCID(gormDB *gorm.DB, redisDB *redis.Client, commentID uint64, limit uint64, tz int) ([]Comment, error)
- func SQLCommentListByList(gormDB *gorm.DB, redisDB *redis.Client, commentList []uint64, tz int) ([]Comment, error)
- func SQLCommentListByTopic(gormDB *gorm.DB, redisDB *redis.Client, topicID uint64, limit uint64, tz int) ([]Comment, error)
- func SQLCommentListByUser(gormDB *gorm.DB, redisDB *redis.Client, userID uint64, limit uint64, tz int) ([]Comment, error)
- type FlarumArticlePageInfo
- type ISQLLoader
- type MainConf
- type POSTHTMLTag
- type POSTMENTION
- type RankMap
- type Reply
- type ReplyLikes
- type RestfulAPIBase
- type RestfulReply
- type RestfulTopic
- type RestfulUser
- type SiteConf
- type SiteInfo
- type Tag
- type Topic
- func SQLArticleGetByID(gormDB *gorm.DB, redisDB *redis.Client, aid uint64) (Topic, error)
- func SQLGetTopicByTag(gormDB *gorm.DB, redisDB *redis.Client, tagID, start uint64, limit uint64) (topics []Topic, err error)
- func SQLGetTopicByUser(gormDB *gorm.DB, userID, start uint64, limit uint64) (topics []Topic, err error)
- func (topic *Topic) CacheCommentList(redisDB *redis.Client, comments []Comment, done chan bool) error
- func (article *Topic) CleanCache()
- func (topic *Topic) CreateFlarumTopic(gormDB *gorm.DB) (bool, error)
- func (topic *Topic) GetCommentIDList(redisDB *redis.Client) (comments []uint64)
- func (article *Topic) GetWeight(redisDB *redis.Client) float64
- type TopicTag
- type USERHTMLTag
- type USERMENTION
- type User
- func RedisGetUserByID(redisDB *redis.Client, uid string) (User, error)
- func SQLGithubRegister(gormDB *gorm.DB, gu *github.User) (User, error)
- func SQLUserGet(gormDB *gorm.DB, _userID string) (User, error)
- func SQLUserGetByEmail(gormDB *gorm.DB, email string) (User, error)
- func SQLUserGetByID(gormDB *gorm.DB, uid uint64) (User, error)
- func SQLUserGetByName(gormDB *gorm.DB, name string) (User, error)
- func SQLUserRegister(gormDB *gorm.DB, name, email, password string) (User, error)
- func (user *User) CachedToRedis(redisDB *redis.Client) error
- func (user *User) CanCreateTopic() bool
- func (user *User) CanEdit(aobjBase *Topic) bool
- func (user *User) CanReply() bool
- func (user *User) CleareRedisCache(redisDB *redis.Client) error
- func (user *User) IsAdmin() bool
- func (user *User) IsForbid() bool
- func (user *User) IsValid() bool
- func (user *User) RefreshCSRF(redisDB *redis.Client) string
- func (user *User) RefreshCache(redisDB *redis.Client)
- func (user *User) SQLGithubSync(gormDB *gorm.DB, gu *github.User)
- func (user *User) SetPreference(gormDB *gorm.DB, preference flarum.Preferences)
- func (user *User) StrID() string
- func (user *User) VerifyCSRFToken(redisDB *redis.Client, token string) bool
- type UserTopic
- type WeightAble
Constants ¶
const ( // FlarumAPIPath flarum 的api位置 FlarumAPIPath = "/api/v1/flarum" FlarumAdminPath = "/admin" FlarumExtensionAPI = "/api/extensions" // 用于网站管理员 )
Variables ¶
var DefaultPreference = flarum.Preferences{
Locale: "en",
}
Functions ¶
func AddNewArticleList ¶
func AddNewArticleList(cid uint64, rankItems []ArticleRankItem)
AddNewArticleList 为某个分类添加话题
func ContentRich ¶
ContentRich 用来转换文本, 转义以及允许用户添加一些富文本样式 该函数效率奇差, 但不会优化
func CreateActionRecord ¶
func FlarumCreateCurrentUser ¶
FlarumCreateCurrentUser 创建用户资源
func FlarumCreateDiscussion ¶
FlarumCreateDiscussion 创建帖子资源
func FlarumCreateForumInfo ¶
func FlarumCreateForumInfo( user *User, appConf AppConf, siteInfo SiteInfo, tags []flarum.Resource, ) flarum.Resource
FlarumCreateForumInfo 从SiteInfo创建ForumInfo tags 当前站点具有的标签集合, TODO: 缓存
func FlarumCreateLocale ¶
FlarumCreateLocale 生成语言包配置
func FlarumCreatePost ¶
FlarumCreatePost 创建评论
func FlarumCreatePostRelations ¶
FlarumCreatePostRelations 创建关系结构
func FlarumCreateTagRelations ¶
FlarumCreateTagRelations 创建关系结构
func FlarumCreateUserLikeRelations ¶
func FlarumCreateUserLikeRelations(userList []uint64) flarum.RelationArray
FlarumCreateUserLikeRelations 点赞关系
func GetArticleCntFromRedisDB ¶
GetArticleCntFromRedisDB 从不同的数据库中获取点击数
func GetAvatarByID ¶
GetAvatarByID 获取用户头像
func GetTopicListByPageNum ¶
GetTopicListByPageNum 通过给定的页码查找话题的ID值
func GetUserNameByID ¶
GetUserNameByID 获取用户名称
func MentionToHTML ¶
func PreProcessUserMention ¶
func PreProcessUserMention(gormDB *gorm.DB, redisDB *redis.Client, tz int, userComment string) string
PreProcessUserMention 预处理用户的引用 #14
func RankMapInit ¶
RankMapInit init a ttl map
func SetCaptchaUseRedisStore ¶
func SetCaptchaUseRedisStore(redisDB *redis.Client)
SetCaptchaUseRedisStore use redis to store captcha
Types ¶
type ActionRecord ¶
type ArticleFeedListItem ¶
type ArticleFeedListItem struct { ID uint64 UID uint64 Name string Cname string Title string AddTimeFmt string EditTimeFmt string Des string }
ArticleFeedListItem rss资源
type ArticleListItem ¶
type ArticleListItem struct { Topic Name string `json:"name"` Avatar string `json:"avatar"` Cname string `json:"cname"` Ruid uint64 `json:"ruid"` Rname string `json:"rname"` AddTimeFmt string `json:"addtimefmt"` EditTimeFmt string `json:"edittimefmt"` /** * When in search page, every article item have the highlight content, * we need tell users that we do not return a random list. */ HighlightContent template.HTML `json:"highlight_content"` }
ArticleListItem data strucy only used in page.
type ArticleMini ¶
ArticleMini 缩略版的Article信息
type ArticlePageInfo ¶
type ArticlePageInfo struct { Items []ArticleListItem `json:"items"` HasPrev bool `json:"hasprev"` HasNext bool `json:"hasnext"` FirstKey uint64 `json:"firstkey"` FirstScore uint64 `json:"firstscore"` LastKey uint64 `json:"lastkey"` PageNum uint64 `json:"pagenum"` PagePrev uint64 `json:"pageprev"` PageNext uint64 `json:"pagenext"` LastScore uint64 `json:"lastscore"` }
ArticlePageInfo data in every list page
type ArticleRankItem ¶
type ArticleRankItem struct { AID uint64 `json:"a_id"` Weight uint64 SQLDB *sql.DB RedisDB *redis.Client }
ArticleRankItem 记录每个话题的权重
type ArticleRelative ¶
type ArticleTag ¶
ArticleTag 文章添加、编辑后传给后台任务的信息 TODO: delete
type CategoryRankData ¶
type CategoryRankData struct { CID uint64 `json:"c_id"` // contains filtered or unexported fields }
CategoryRankData 一个分类下的排序数据
type Comment ¶
type Comment struct { Reply Avatar string `json:"avatar"` ContentFmt template.HTML Likes []uint64 // 点赞的用户 }
Comment 评论信息
func SQLCommentByID ¶
SQLCommentByID 获取一条评论
func SQLCommentListByCID ¶
func SQLCommentListByCID(gormDB *gorm.DB, redisDB *redis.Client, commentID uint64, limit uint64, tz int) ([]Comment, error)
SQLCommentListByCID 获取某条评论
func SQLCommentListByList ¶
func SQLCommentListByList(gormDB *gorm.DB, redisDB *redis.Client, commentList []uint64, tz int) ([]Comment, error)
SQLCommentListByList 获取某条评论
func SQLCommentListByTopic ¶
func SQLCommentListByTopic(gormDB *gorm.DB, redisDB *redis.Client, topicID uint64, limit uint64, tz int) ([]Comment, error)
SQLCommentListByTopic 获取帖子的所有评论
func SQLCommentListByUser ¶
func SQLCommentListByUser(gormDB *gorm.DB, redisDB *redis.Client, userID uint64, limit uint64, tz int) ([]Comment, error)
SQLCommentListByUser 获取某个用户的帖子信息
func (*Comment) CreateFlarumComment ¶
CreateFlarumComment 创建flarum的评论
type FlarumArticlePageInfo ¶
type FlarumArticlePageInfo struct { Items []flarum.Discussion LinkFirst string LinkPrev string LinkNext string }
FlarumArticlePageInfo flarum站点的数据信息
type ISQLLoader ¶
type ISQLLoader interface {
LoadDictData(map[string]interface{})
}
ISQLLoader dict结果的loader
type MainConf ¶
type MainConf struct { HTTPPort int Domain string // 若启用https 则该domain 为注册的域名,eg: domain.com、www.domain.com BaseURL string // 数据库地址 MySQLURL string MongoURL string RedisURL string StaticDir string WebpackDir string LocaleDir string ExtensionsDir string ViewDir string Debug bool ServerName string CookieSecure bool CookieHttpOnly bool OldSiteDomain string TLSCrtFile string TLSKeyFile string // secure cookie 初始化时需要 SCHashKey string SCBlockKey string }
MainConf 主配置
type POSTHTMLTag ¶
type POSTHTMLTag struct { XMLName xml.Name `xml:"a"` Text string `xml:",chardata"` Href string `xml:"href,attr"` Class string `xml:"class,attr"` DataID string `xml:"data-id,attr"` }
POSTHTMLTag 引用其他评论的tag
type POSTMENTION ¶
type POSTMENTION struct { XMLName xml.Name `xml:"POSTMENTION"` Text string `xml:",chardata"` Discussionid string `xml:"discussionid,attr"` Displayname string `xml:"displayname,attr"` ID string `xml:"id,attr"` Number string `xml:"number,attr"` Username string `xml:"username,attr"` }
POSTMENTION 引用评论
type RankMap ¶
type RankMap struct { GormDB *gorm.DB SQLDB *sql.DB RedisDB *redis.Client // contains filtered or unexported fields }
RankMap time to live map
type Reply ¶
type Reply struct { gorm.Model ID uint64 `gorm:"primaryKey"` AID uint64 `gorm:"column:topic_id"` UID uint64 `gorm:"column:user_id"` Number uint64 `json:"number"` Content string `json:"content"` ClientIP string `json:"clientip"` AddTime uint64 `json:"addtime"` }
Reply 会在数据库中保存的信息
type ReplyLikes ¶
type RestfulAPIBase ¶
type RestfulAPIBase struct {
State bool `json:"success"`
}
RestfulAPIBase for restful API
type RestfulTopic ¶
type RestfulTopic struct { ID uint64 `json:"id"` UID uint64 `json:"author_id"` Content template.HTML `json:"content"` Title string `json:"title"` CreateAt string `json:"create_at"` Author RestfulUser `json:"author"` ReplyCount uint64 `json:"reply_count"` VisitCount uint64 `json:"visit_count"` Replies []RestfulReply `json:"replies"` LastReplyAt string `json:"last_reply_at"` }
RestfulTopic topic for restful API
type RestfulUser ¶
RestfulUser user for restful API
type SiteConf ¶
type SiteConf struct { GoVersion string MD5Sums string Name string Desc string AdminEmail string MainDomain string // 上传图片后添加网址前缀, eg: http://domian.com 、http://234.21.35.89:8082 CDNBaseURL string // 静态文件cdn地址 MainNodeIDs string TimeZone int HomeShowNum int TitleMaxLen int ContentMaxLen int PostInterval int CommentListNum int CommentInterval int Authorized bool RegReview bool CloseReg bool AutoDataBackup bool AutoGetTag bool UploadSuffix string UploadImgOnly bool UploadImgResize bool AllowSignup bool UploadMaxSize int UploadMaxSizeByte int64 WelcomeMessage string WelcomeTitle string // Google tracking code id TrackingCodeID string GithubClientID string GithubClientSecret string }
SiteConf 站点配置
type SiteInfo ¶
type SiteInfo struct { Days uint64 // 创建的天数 UserNum uint64 // 用户数量 NodeNum uint64 // 节点数量 TagNum uint64 // tag数量 PostNum uint64 // 帖子数量 ReplyNum uint64 // 回复数量 }
SiteInfo 当前站点的一些集合类信息
type Tag ¶
type Tag struct { gorm.Model ID uint64 `gorm:"primaryKey"` Name string `json:"name" gorm:"index:idx_name,unique"` URLName string `json:"urlname" gorm:"index:idx_urlname,unique"` Articles uint64 `json:"articles"` About string `json:"about"` ParentID uint64 `json:"parent_id"` Position uint64 `json:"position"` Description string `json:"description"` Hidden bool `json:"hidden"` Color string `json:"color"` IconIMG string `json:"icon_img"` Topics []Topic `gorm:"many2many:topic_tags;"` }
Tag 帖子分类
func SQLGetTagByUrlName ¶
func (*Tag) CreateFlarumTag ¶
type Topic ¶
type Topic struct { gorm.Model ID uint64 `gorm:"primaryKey"` UserID uint64 `gorm:"column:user_id;index"` Title string `json:"title"` Content string `json:"content"` FirstPostID uint64 LastPostID uint64 LastPostUserID uint64 CommentCount uint64 ClientIP string `json:"clientip"` IsSticky bool Tags []Tag `gorm:"many2many:topic_tags;"` }
Topic 基础的文档类, 在数据库表中的字段
func SQLArticleGetByID ¶
SQLArticleGetByID 通过 article id获取内容
func SQLGetTopicByTag ¶
func SQLGetTopicByTag(gormDB *gorm.DB, redisDB *redis.Client, tagID, start uint64, limit uint64) (topics []Topic, err error)
tagID 为0 表示全部主题
func SQLGetTopicByUser ¶
func (*Topic) CacheCommentList ¶
func (topic *Topic) CacheCommentList(redisDB *redis.Client, comments []Comment, done chan bool) error
CacheCommentList 缓存当前话题对应的评论ID, 该函数可以用于进行增加或是减少 注意这里是有顺序的, 顺序为发帖时间
func (*Topic) CleanCache ¶
func (article *Topic) CleanCache()
func (*Topic) CreateFlarumTopic ¶
CreateFlarumTopic 创建flarum的帖子 帖子中, category和tag是不同的数据 category是帖子比较大的分类, 每个帖子只能有一个 tag只是这个帖子具有的某种特征, 每个帖子可以有多个tag
func (*Topic) GetCommentIDList ¶
GetCommentIDList 获取帖子已经排序好的评论列表
type TopicTag ¶
type TopicTag struct { gorm.Model TopicID uint64 `gorm:"primaryKey"` TagID uint64 `gorm:"primaryKey"` }
TopicTags 帖子的标签 使用gorm 的many2many, 不需要单独初始化了
type USERHTMLTag ¶
type USERHTMLTag struct { XMLName xml.Name `xml:"a"` Text string `xml:",chardata"` Href string `xml:"href,attr"` Class string `xml:"class,attr"` }
USERHTMLTag 引用用户的tag
type USERMENTION ¶
type USERMENTION struct { XMLName xml.Name `xml:"USERMENTION"` Text string `xml:",chardata"` Displayname string `xml:"displayname,attr"` ID string `xml:"id,attr"` Username string `xml:"username,attr"` }
USERMENTION 引用用户
type User ¶
type User struct { gorm.Model ID uint64 `gorm:"primaryKey"` Name string `json:"name" gorm:"index:idx_name,unique"` Nickname string `json:"nickname"` Gender string `json:"gender"` Flag int `json:"flag"` Avatar string `json:"avatar"` Password string `json:"password"` Email string `json:"email"` URL string `json:"url"` Articles uint64 `json:"articles"` Replies uint64 `json:"replies"` About string `json:"about"` Hidden bool `json:"hidden"` Session string `json:"session"` Token string `json:"token"` Description string WebSite string Reputation uint64 `json:"reputation"` // 声望值 // Preferences *flarum.Preferences `gorm:"foreignKey:PreferencesRefer"` Preferences []byte }
User store in database
func RedisGetUserByID ¶
RedisGetUserByID 从Redis中获取缓存的用户
func SQLGithubRegister ¶
SQLGithubRegister github用户注册
func SQLUserGet ¶
SQLUserGet 获取用户 当你不确定用户传来的是用户名还是用户id时, 可以调用该函数获取用户
func SQLUserGetByEmail ¶
SQLUserGetByEmail 获取数据库中用户
func SQLUserGetByID ¶
SQLUserGetByID 获取数据库用户
func SQLUserGetByName ¶
SQLUserGetByName 获取数据库中用户
func SQLUserRegister ¶
func (*User) CachedToRedis ¶
CachedToRedis 缓存当前用户的信息至Redis
func (*User) CleareRedisCache ¶
CleareRedisCache 缓存当前用户的信息至Redis
func (*User) RefreshCSRF ¶
RefreshCSRF 刷新CSRF token
func (*User) RefreshCache ¶
func (user *User) RefreshCache(redisDB *redis.Client)
RefreshCache 刷新当前用户的信息
func (*User) SQLGithubSync ¶
SQLGithubSync github用户同步信息
func (*User) SetPreference ¶
func (user *User) SetPreference(gormDB *gorm.DB, preference flarum.Preferences)
SetPreference 更新用户配置信息 数据库中使用了blob的数据类型, 查看数据时, 需要进行转换:
SELECT CONVERT(`preferences` USING utf8) FROM `user`;
func (*User) VerifyCSRFToken ¶
VerifyCSRFToken 确认用户CSRF token
type UserTopic ¶
type UserTopic struct { gorm.Model ID uint64 `gorm:"primaryKey"` UserID uint64 `gorm:"column:user_id;index"` TopicID uint64 `gorm:"column:topic_id;index"` LastReadAt time.Time // last read time LastReadPostNumber uint64 // last read post number Subscription string // subscription status enum(follow, ignore) }
It will record the user relation with the topic