models

package
v0.0.0-...-a5e9c71 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2015 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Db    *mgo.Database //数据库
	Redis redis.Client  //redis
)

Functions

func AutoCache

func AutoCache(key string, obj interface{}, time int64, callback func())

自动读存缓存

func DeleteCache

func DeleteCache(key string)

删除某个缓存

func StructDecode

func StructDecode(data []byte, to interface{}) error

字节流解码为结构体

func StructEncode

func StructEncode(data interface{}) ([]byte, error)

结构体编码为字节流

Types

type Article

type Article struct {
	Id       bson.ObjectId `bson:"_id" json:"_id" form:"_id"` // 主键
	Uid      bson.ObjectId `bson:"u" json:"u" form:"u"`       // 所有者id
	Lid      string        `bson:"l" json:"l" form:"l"`       // 最后回复者id
	Category int           `bson:"c" json:"c" form:"c"`       // 所属分类id 0:问答 1:分享
	Title    string        `bson:"t" json:"t" form:"t"`       // 标题
	Content  string        `bson:"co" json:"co" form:"co"`    // 正文内容
	Views    uint32        `bson:"v" json:"v" form:"v"`       // 浏览量
	Reply    uint32        `bson:"r" json:"r" form:"r"`       // 回复量
	Tag      []string      `bson:"ta" json:"ta" form:"ta"`    // 标签
	Top      int           `bson:"tp" json:"tp" form:"tp"`    // 置顶优先级
	Time     time.Time     `bson:"tm" json:"tm" form:"tm"`    // 发布日期
	TimeLast time.Time     `bson:"tl" json:"tl" form:"tl"`    // 最后挖坟日期
}

func (*Article) AddReply

func (this *Article) AddReply()

为某个文章增加评论 会同时更新挖坟日期

func (*Article) AddTag

func (this *Article) AddTag(name string)

新增标签

func (*Article) AddViews

func (this *Article) AddViews()

为某个文章增加浏览数

func (*Article) Count

func (this *Article) Count(category int) int

查询总数

func (*Article) Delete

func (this *Article) Delete()

删除文章

func (*Article) Find

func (this *Article) Find(category int, from int, number int) []*Article

查询区间段最新文章

func (*Article) FindByTag

func (this *Article) FindByTag(tag string, from int, number int) []*Article

根据标签查询列表

func (*Article) FindOne

func (this *Article) FindOne(id string) (bool, interface{})

func (*Article) FindTagCount

func (this *Article) FindTagCount(tag string) int

查询指定游戏某标签的话题数

func (*Article) FindUserArticles

func (this *Article) FindUserArticles(id bson.ObjectId, from int, number int) []*Article

查询某用文章

func (*Article) FindUserArticlesCount

func (this *Article) FindUserArticlesCount(id bson.ObjectId) int

查询某用文章数量

func (*Article) FindUserCold

func (this *Article) FindUserCold(id bson.ObjectId) []*Article

查询某用户冷门文章前10个

func (*Article) FindUserHot

func (this *Article) FindUserHot(id bson.ObjectId) []*Article

查询某用户热评文章前10个

func (*Article) GetId

func (this *Article) GetId()

获取id

func (*Article) Insert

func (this *Article) Insert() (bool, interface{})

插入文章

func (*Article) RemoveTag

func (this *Article) RemoveTag(name string)

删除标签

func (*Article) Same

func (this *Article) Same() []*Article

查询拥有相同标签的文章

func (*Article) SetTop

func (this *Article) SetTop()

设置置顶数

func (*Article) UpdateCategory

func (this *Article) UpdateCategory(category int) bool

更新分类

func (*Article) UpdateContent

func (this *Article) UpdateContent()

更新内容 会同时更新挖坟日期

func (*Article) UpdateLastReply

func (this *Article) UpdateLastReply(id string, image string)

更新某文章最后评论人信息

func (*Article) UpdateTop

func (this *Article) UpdateTop()

更新置顶参数

type Base

type Base struct {
	Id bson.ObjectId `json:"_id" form:"_id" bson:"_id" valid:"Required"` //主键
}

func (*Base) Count

func (this *Base) Count() int

type Member

type Member struct {
	Id            bson.ObjectId `bson:"_id" json:"_id"`         // 主键
	NickName      string        `bson:"n" json:"n" form:"n"`    // 昵称
	Login         string        `bson:"l" json:"l" form:"l"`    // github登陆名
	Image         string        `bson:"i" json:"i" form:"i"`    // 用户头像
	Token         string        `bson:"to" json:"to" form:"to"` // github对应token
	ArticleNumber int           `bson:"a" json:"a" form:"a"`    // 文章发表量
	ReplyNumber   int           `bson:"r" json:"r" form:"r"`    // 评论数量
	UploadSize    int64         `bson:"u" json:"u" form:"u"`    // 上传量
	Time          time.Time     `bson:"t" json:"t" form:"t"`    // 注册时间
	Admin         bool          `bson:"ad" json:"ad" form:"ad"` // 是否为管理员
}

func (*Member) AddArticleNumber

func (this *Member) AddArticleNumber()

增加文章发表量

func (*Member) AddReplyNumber

func (this *Member) AddReplyNumber()

增加评论量

func (*Member) FindArticles

func (this *Member) FindArticles(articles []*Article) []*Member

查询文章用户信息

func (*Member) FindOne

func (this *Member) FindOne(value string) (bool, interface{})

根据ObjectId查询某个用户信息

func (*Member) FindReplys

func (this *Member) FindReplys(replys []*Reply) []*Member

查询评论用户信息

func (*Member) FindToken

func (this *Member) FindToken(token string) (bool, interface{})

根据code查找用户

func (*Member) Insert

func (this *Member) Insert() (bool, interface{})

func (*Member) Remove

func (this *Member) Remove() bool

删除用户

func (*Member) Save

func (this *Member) Save()

保存

type Party

type Party struct {
	Id          string        `bson:"_id" json:"_id" form:"_id"` //第三方平台id
	Type        string        `bson:"t" json:"t" form:"t"`       //第三方平台类型
	MemberId    bson.ObjectId `bson:"mi" json:"mi" form:"mi"`    //用户id
	AccessToken string        `bson:"at" json:"at" form:"at"`    //用户token
	Name        string        `bson:"n" json:"n" form:"n"`       //用户昵称
	Image       string        `bson:"i" json:"i" form:"i"`       //用户头像地址
	ExpiresTime time.Time     `bson:"e" json:"e" form:"e"`       //授权过期时间
}

func (*Party) ChangeMember

func (this *Party) ChangeMember(id string, memberId bson.ObjectId)

修改第三方平台对应用户id

func (*Party) FindBinds

func (this *Party) FindBinds(memberId bson.ObjectId) []*Party

查询某用户绑定的平台信息

func (*Party) FindMember

func (this *Party) FindMember(id string, _type string) bool

根据平台id和类型查询用户id

func (*Party) IdExist

func (this *Party) IdExist(id string) bool

查询该id是否存在

func (*Party) Insert

func (this *Party) Insert(id string, _type string, memberid string, accesstoken string, name string, image string, expresin string)

绑定第三方平台

func (*Party) RefreshAuthor

func (this *Party) RefreshAuthor(id string, _type string, token string, expresin string)

更新第三方平台token和授权时间

type Reply

type Reply struct {
	Id      bson.ObjectId `bson:"_id" json:"_id" form:"_id"` // 主键
	Article bson.ObjectId `bson:"a" json:"a" form:"a"`       // 所属文章id
	Uid     bson.ObjectId `bson:"u" json:"u" form:"u"`       // 所有者id
	Content string        `bson:"co" json:"co" form:"co"`    // 内容
	Time    time.Time     `bson:"tm" json:"tm" form:"tm"`    // 发布日期
}

func (*Reply) DeletArticleReply

func (this *Reply) DeletArticleReply(article bson.ObjectId)

删除某个帖子下全部回复和评论

func (*Reply) Find

func (this *Reply) Find(article string, from int, number int) []*Reply

查询区间段最新文章

func (*Reply) GetId

func (this *Reply) GetId()

获取id

func (*Reply) Insert

func (this *Reply) Insert() (bool, interface{})

插入评论

func (*Reply) Reply

func (this *Reply) Reply() (bool, interface{})

插入评论

type Tag

type Tag struct {
	Id     bson.ObjectId `bson:"_id" form:"_id" json:"_id"` // 主键
	Author bson.ObjectId `bson:"a" form:"a" json:"a"`       // 作者id
	Name   string        `bson:"n" form:"n" json:"n"`       // 名称
	Count  int           `bson:"c" form:"c" json:"c"`       // 文章总数
}

func (*Tag) CountReduce

func (this *Tag) CountReduce(name string)

文章数减少1

func (*Tag) Hot

func (this *Tag) Hot() []*Tag

查询文章总数最多的前30个标签

func (*Tag) Insert

func (this *Tag) Insert() (bool, interface{})

插入

func (*Tag) Like

func (this *Tag) Like(key string) []*Tag

模糊查询

func (*Tag) Upsert

func (this *Tag) Upsert(name string) bool

不存在则创建,存在累加文章总数

Jump to

Keyboard shortcuts

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