Documentation ¶
Index ¶
- func GetStringKey(id uint64) string
- func IdToBytes(intId uint64) []byte
- func RandomBytes(minLen, maxLen int) []byte
- type Article
- type ArticleExpiredCallback
- type ArticleMgr
- func (m *ArticleMgr) Add(article *Article) (uint64, error)
- func (m *ArticleMgr) Close() error
- func (m *ArticleMgr) Count() uint64
- func (m *ArticleMgr) Delete(id uint64) error
- func (m *ArticleMgr) GetById(id uint64) (*Article, error)
- func (m *ArticleMgr) GetMaxId() uint64
- func (m *ArticleMgr) Next(id uint64, n int) []*Article
- func (m *ArticleMgr) Open(path string) error
- func (m *ArticleMgr) Prev(id uint64, n int) []*Article
- func (m *ArticleMgr) Update(article *Article) error
- type Config
- type GModel
- func (m *GModel) AddArticle(tags []string, data string, ttl int64) (uint64, error)
- func (m *GModel) Close() error
- func (m *GModel) DeleteArticle(articleId uint64) error
- func (m *GModel) GetArticle(articleId uint64) (*Article, error)
- func (m *GModel) GetArticleCount() uint64
- func (m *GModel) GetArticleCountByTag(tagName string) uint64
- func (m *GModel) GetMaxArticleId() uint64
- func (m *GModel) GetNextArticles(articleId uint64, n int) []*Article
- func (m *GModel) GetNextArticlesByTag(tagName string, articleId uint64, n int) []*Article
- func (m *GModel) GetNextTags(name string, n int) []*Tag
- func (m *GModel) GetPrevArticles(articleId uint64, n int) []*Article
- func (m *GModel) GetPrevArticlesByTag(tagName string, articleId uint64, n int) []*Article
- func (m *GModel) GetPrevTags(name string, n int) []*Tag
- func (m *GModel) GetTagById(id uint64) (*Tag, error)
- func (m *GModel) GetTagByName(name string) (*Tag, error)
- func (m *GModel) GetTagCount() uint64
- func (m *GModel) Open(conf *Config) error
- func (m *GModel) RenameTag(oldName, newName string) error
- func (m *GModel) UpdateArticle(articleId uint64, newTags []string, newData string, newTTL int64) error
- type IdMgr
- func (m *IdMgr) AddIntId(intId uint64) (string, error)
- func (m *IdMgr) Close() error
- func (m *IdMgr) Count() uint64
- func (m *IdMgr) GetIntId(stringId string) (uint64, bool)
- func (m *IdMgr) GetStringId(intId uint64) (string, bool)
- func (m *IdMgr) Open(path string) error
- func (m *IdMgr) SetIdMap(intId uint64, stringId string) error
- type KVStore
- func (kv *KVStore) Close() error
- func (kv *KVStore) Count() uint64
- func (kv *KVStore) CurrentSequence() uint64
- func (kv *KVStore) Delete(key []byte) error
- func (kv *KVStore) Get(key []byte) ([]byte, error)
- func (kv *KVStore) Has(key []byte) bool
- func (kv *KVStore) Next(key []byte, n int) [][]byte
- func (kv *KVStore) NextSequence() (uint64, error)
- func (kv *KVStore) Open(path string) error
- func (kv *KVStore) Prev(key []byte, n int) [][]byte
- func (kv *KVStore) Put(key, value []byte) error
- type KeyExpiredCallback
- type TTLCache
- func (c *TTLCache) Close() error
- func (c *TTLCache) Count() uint64
- func (c *TTLCache) Delete(key []byte) error
- func (c *TTLCache) Get(key []byte) ([]byte, error)
- func (c *TTLCache) Has(key []byte) bool
- func (c *TTLCache) Open(dataDBPath, ttlDBPath string) error
- func (c *TTLCache) Put(key, value []byte, ttl int64) error
- type TTLChecker
- func (c *TTLChecker) Close() error
- func (c *TTLChecker) Delete(key []byte) error
- func (c *TTLChecker) GetInfo(key []byte) (*TTLInfo, error)
- func (c *TTLChecker) GetKeyCount() uint64
- func (c *TTLChecker) Open(path string, callback KeyExpiredCallback) error
- func (c *TTLChecker) SetTTL(key []byte, createTime, ttl int64) error
- type TTLIdMgr
- func (m *TTLIdMgr) AddIntId(intId uint64, ttl int64) (string, error)
- func (m *TTLIdMgr) Close() error
- func (m *TTLIdMgr) Count() uint64
- func (m *TTLIdMgr) GetIntId(stringId string) (uint64, bool)
- func (m *TTLIdMgr) GetStringId(intId uint64) (string, bool)
- func (m *TTLIdMgr) Open(path string) error
- func (m *TTLIdMgr) SetIdMap(intId uint64, stringId string, ttl int64) error
- type TTLInfo
- type Tag
- type TagMgr
- func (m *TagMgr) Add(name string) (uint64, error)
- func (m *TagMgr) AddArticleCountForId(id uint64, count int64) (uint64, error)
- func (m *TagMgr) AddArticleCountForName(name string, count int64) (uint64, error)
- func (m *TagMgr) Close() error
- func (m *TagMgr) Count() uint64
- func (m *TagMgr) DeleteById(id uint64) error
- func (m *TagMgr) DeleteByName(name string) error
- func (m *TagMgr) GetArticleCountById(id uint64) uint64
- func (m *TagMgr) GetArticleCountByName(name string) uint64
- func (m *TagMgr) GetById(id uint64) (*Tag, error)
- func (m *TagMgr) GetByName(name string) (*Tag, error)
- func (m *TagMgr) Next(id uint64, n int) []*Tag
- func (m *TagMgr) NextByName(name string, n int) []*Tag
- func (m *TagMgr) Open(path string) error
- func (m *TagMgr) Prev(id uint64, n int) []*Tag
- func (m *TagMgr) PrevByName(name string, n int) []*Tag
- func (m *TagMgr) Rename(oldName string, newName string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStringKey ¶
将uint64转成string,不足20位时左边补0,作用同 GetStringKey 注意:uint64最大值是 18446744073709551615,长度为 20
func RandomBytes ¶
得到一个长度在区间[minLen, maxLen]内的随机字符数组 一般6位长度就够了:62^6 = 56800235584 = 568亿
Types ¶
type ArticleExpiredCallback ¶
type ArticleExpiredCallback = func(article *Article)
注意:回调中不能修改 article
type ArticleMgr ¶
type ArticleMgr struct {
// contains filtered or unexported fields
}
func (*ArticleMgr) Close ¶
func (m *ArticleMgr) Close() error
func (*ArticleMgr) Next ¶
func (m *ArticleMgr) Next(id uint64, n int) []*Article
返回指定文章ID的后N篇文章(不包括当前id) 如果id等于0,则表示获取最旧的N篇文章
type Config ¶
type Config struct { ArticleDBPath string // 文章数据库路径 TagDBPath string // 文章的分类数据库路径 IndexDBPath string // 索引数据库路径 TTLDBPath string // TTL数据库路径,用于存储每篇文章的生命周期 ArticleExpiredCallback ArticleExpiredCallback // 文章过期的回调 }
type GModel ¶
type GModel struct {
// contains filtered or unexported fields
}
封装 article 和 tag 两个模块,方便外部使用
func (*GModel) AddArticle ¶
增加文章,返回文章ID tags: 文章分类名称,可以为空,tags为空表示该文章属于未分类 data: 文章数据内容,不能为空 ttl: 文章生命周期,单位:秒,大于0才生效,否则其生命周期为永久
func (*GModel) GetArticleCountByTag ¶
返回分类下的文章数量
func (*GModel) GetNextArticles ¶
获取指定文章的后N篇(不包括当前这篇) 如果 articleId 等于 0,则表示获取最旧的N篇文章(id最小的N篇)
func (*GModel) GetNextArticlesByTag ¶
获取指定文章的后N篇(不包括当前这篇),保证这N篇文章的分类为tagName tagName为文章分类,如果tag不存在,则返回空数组,如果tag为空,则表示未分类,会返回未分类的文章 articleId为文章ID,如果articleId为0,则返回该分类最旧的N篇文章(id最小的N篇)
func (*GModel) GetNextTags ¶
返回指定分类的后N个分类(不包括当前分类) 如果分类不存在,则表示获取最旧的N个分类
func (*GModel) GetPrevArticles ¶
获取指定文章的前N篇(不包括当前这篇) 如果 articleId 大于 最大的文章ID,则表示获取最新的N篇文章(id最大的N篇)
func (*GModel) GetPrevArticlesByTag ¶
获取指定文章的前N篇(不包括当前这篇),保证这N篇文章的分类为tagName tagName为文章分类,如果tag不存在,则返回空数组,如果tag为空,则表示未分类,会返回未分类的文章 articleId为文章ID,如果 articleId 大于 最大的文章ID,则返回该分类最新的N篇文章(id最大的N篇)
func (*GModel) GetPrevTags ¶
返回指定分类的前N个分类(不包括当前分类) 如果分类不存在,则表示获取最新的N个分类
type IdMgr ¶
type IdMgr struct { // 字符串ID的长度,注意这个是期望值,如果冲突太多,则会自动增加位数 // 默认为 8 StringIdLength int // contains filtered or unexported fields }
ID是递增的,所以不需要考虑删除,只管做映射即可 这个类的作用:将整型ID和字符串ID互相映射 只能转换整型ID到字符串ID
type KVStore ¶
type KVStore struct {
// contains filtered or unexported fields
}
func (*KVStore) Next ¶
返回指定key后面的n个key(不包括当前key,当前key也可以不存在) 如果当前key为空数组或者nil,表示从头开始遍历 如果当前key为字典序最大,则返回的结果为空;如果当前key为字典序最小,则返回最前的n个key 注意:leveldb 是根据 key 的字典序排序的
func (*KVStore) NextSequence ¶
生成并返回下一个Sequence 注意这是一个读写操作
type TTLChecker ¶
type TTLChecker struct {
// contains filtered or unexported fields
}
func (*TTLChecker) Close ¶
func (c *TTLChecker) Close() error
func (*TTLChecker) Delete ¶
func (c *TTLChecker) Delete(key []byte) error
func (*TTLChecker) GetKeyCount ¶
func (c *TTLChecker) GetKeyCount() uint64
func (*TTLChecker) Open ¶
func (c *TTLChecker) Open(path string, callback KeyExpiredCallback) error
type TTLIdMgr ¶
type TTLIdMgr struct { // 字符串ID的长度,注意这个是期望值,如果冲突太多,则会自动增加位数 // 默认为 8 StringIdLength int // contains filtered or unexported fields }
这个类的作用:将整型ID和字符串ID互相映射,允许设置映射记录的有效期,避免数据库膨胀 只能转换整型ID到字符串ID
func (*TTLIdMgr) GetStringId ¶
获取整型ID对应的字符串ID
type TTLInfo ¶
type TagMgr ¶
type TagMgr struct {
// contains filtered or unexported fields
}
分类管理器
func (*TagMgr) AddArticleCountForId ¶
增加(或减少)指定分类下的文章数量 返回更新后该分类下的文章数量
func (*TagMgr) AddArticleCountForName ¶
增加(或减少)指定分类下的文章数量 返回更新后该分类下的文章数量
func (*TagMgr) GetArticleCountById ¶
获取指定分类下的文章数量
func (*TagMgr) GetArticleCountByName ¶
获取指定分类下的文章数量
func (*TagMgr) NextByName ¶
返回指定分类的后N个分类(不包括当前分类) 如果分类不存在,则表示获取最旧的N个分类
func (*TagMgr) PrevByName ¶
返回指定分类的前N个分类(不包括当前分类) 如果分类不存在,则表示获取最新的N个分类