Documentation ¶
Overview ¶
Package engine defines interfaces each supported storage should implement. Includes default implementation with boltdb
Index ¶
- type Accessor
- type Admin
- type BoltDB
- func (b *BoltDB) Blocked(siteID string) (users []store.BlockedUser, err error)
- func (b *BoltDB) Close() error
- func (b *BoltDB) Count(locator store.Locator) (count int, err error)
- func (b *BoltDB) Create(comment store.Comment) (commentID string, err error)
- func (b *BoltDB) Delete(locator store.Locator, commentID string, mode store.DeleteMode) error
- func (b *BoltDB) DeleteAll(siteID string) error
- func (b *BoltDB) DeleteUser(siteID string, userID string) error
- func (b *BoltDB) Find(locator store.Locator, sortFld string) (comments []store.Comment, err error)
- func (b *BoltDB) Get(locator store.Locator, commentID string) (comment store.Comment, err error)
- func (b *BoltDB) Info(locator store.Locator, readOnlyAge int) (store.PostInfo, error)
- func (b *BoltDB) IsBlocked(siteID string, userID string) (blocked bool)
- func (b *BoltDB) IsReadOnly(locator store.Locator) (ro bool)
- func (b *BoltDB) IsVerified(siteID string, userID string) (verified bool)
- func (b *BoltDB) Last(siteID string, max int) (comments []store.Comment, err error)
- func (b BoltDB) List(siteID string, limit, skip int) (list []store.PostInfo, err error)
- func (b *BoltDB) Put(locator store.Locator, comment store.Comment) error
- func (b *BoltDB) SetBlock(siteID string, userID string, status bool, ttl time.Duration) error
- func (b *BoltDB) SetReadOnly(locator store.Locator, status bool) error
- func (b *BoltDB) SetVerified(siteID string, userID string, status bool) error
- func (b *BoltDB) User(siteID, userID string, limit, skip int) (comments []store.Comment, err error)
- func (b *BoltDB) UserCount(siteID, userID string) (int, error)
- func (b *BoltDB) Verified(siteID string) (ids []string, err error)
- type BoltSite
- type Interface
- type Mongo
- func (m *Mongo) Blocked(siteID string) (users []store.BlockedUser, err error)
- func (m *Mongo) Close() error
- func (m *Mongo) Count(locator store.Locator) (count int, err error)
- func (m *Mongo) Create(comment store.Comment) (commentID string, err error)
- func (m *Mongo) Delete(locator store.Locator, commentID string, mode store.DeleteMode) error
- func (m *Mongo) DeleteAll(siteID string) error
- func (m *Mongo) DeleteUser(siteID string, userID string) error
- func (m *Mongo) Find(locator store.Locator, sortFld string) (comments []store.Comment, err error)
- func (m *Mongo) Get(locator store.Locator, commentID string) (comment store.Comment, err error)
- func (m *Mongo) Info(locator store.Locator, readOnlyAge int) (info store.PostInfo, err error)
- func (m *Mongo) IsBlocked(siteID string, userID string) (blocked bool)
- func (m *Mongo) IsReadOnly(locator store.Locator) (ro bool)
- func (m *Mongo) IsVerified(siteID string, userID string) (verified bool)
- func (m *Mongo) Last(siteID string, max int) (comments []store.Comment, err error)
- func (m *Mongo) List(siteID string, limit, skip int) (list []store.PostInfo, err error)
- func (m *Mongo) Put(locator store.Locator, comment store.Comment) error
- func (m *Mongo) SetBlock(siteID string, userID string, status bool, ttl time.Duration) error
- func (m *Mongo) SetReadOnly(locator store.Locator, status bool) (err error)
- func (m *Mongo) SetVerified(siteID string, userID string, status bool) error
- func (m *Mongo) User(siteID, userID string, limit, skip int) (comments []store.Comment, err error)
- func (m *Mongo) UserCount(siteID, userID string) (count int, err error)
- func (m *Mongo) Verified(siteID string) (ids []string, err error)
- type UserRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accessor ¶
type Accessor interface { Create(comment store.Comment) (commentID string, err error) // create new comment, avoid dups by id Get(locator store.Locator, commentID string) (store.Comment, error) // get comment by id Put(locator store.Locator, comment store.Comment) error // update comment, mutable parts only Find(locator store.Locator, sort string) ([]store.Comment, error) // find comments for locator Last(siteID string, limit int) ([]store.Comment, error) // last comments for given site, sorted by time User(siteID, userID string, limit, skip int) ([]store.Comment, error) // comments by user, sorted by time UserCount(siteID, userID string) (int, error) // comments count by user Count(locator store.Locator) (int, error) // number of comments for the post List(siteID string, limit int, skip int) ([]store.PostInfo, error) // list of commented posts Info(locator store.Locator, readonlyAge int) (store.PostInfo, error) // get post info Close() error // close/stop engine }
Accessor defines all usual access ops avail for regular user
type Admin ¶
type Admin interface { Delete(locator store.Locator, commentID string, mode store.DeleteMode) error // delete comment by id DeleteAll(siteID string) error // delete all data from site DeleteUser(siteID string, userID string) error // remove all comments from user SetBlock(siteID string, userID string, status bool, ttl time.Duration) error // block or unblock user with TTL (0-permanent) IsBlocked(siteID string, userID string) bool // check if user blocked Blocked(siteID string) ([]store.BlockedUser, error) // get list of blocked users SetReadOnly(locator store.Locator, status bool) error // set/reset read-only flag IsReadOnly(locator store.Locator) bool // check if post read-only SetVerified(siteID string, userID string, status bool) error // set/reset verified flag IsVerified(siteID string, userID string) bool // check verified status Verified(siteID string) ([]string, error) // list of verified user ids }
Admin defines all store ops avail for admin only
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
BoltDB implements store.Interface, represents multiple sites with multiplexing to different bolt dbs. Thread safe. there are 5 types of top-level buckets:
- comments for post in "posts" top-level bucket. Each url (post) makes its own bucket and each k:v pair is commentID:comment
- history of all comments. They all in a single "last" bucket (per site) and key is defined by ref struct as ts+commentID value is not full comment but a reference combined from post-url+commentID
- user to comment references in "users" bucket. It used to get comments for user. Key is userID and value is a nested bucket named userID with kv as ts:reference
- blocking info sits in "block" bucket. Key is userID, value - ts
- counts per post to keep number of comments. Key is post url, value - count
- readonly per post to keep status of manually set RO posts. Key is post url, value - ts
func (*BoltDB) Blocked ¶
func (b *BoltDB) Blocked(siteID string) (users []store.BlockedUser, err error)
Blocked get lists of blocked users for given site bucket uses userID:
func (*BoltDB) Create ¶
Create saves new comment to store. Adds to posts bucket, reference to last and user bucket and increments count bucket
func (*BoltDB) Delete ¶
Delete removes comment, by locator from the store. Posts collection only sets status to deleted and clear fields in order to prevent breaking trees of replies. From last bucket removed for real.
func (*BoltDB) DeleteUser ¶
DeleteUser removes all comments for given user. Everything will be market as deleted and user name and userID will be changed to "deleted". Also removes from last and from user buckets.
func (*BoltDB) IsReadOnly ¶
IsReadOnly checks if post in RO mode
func (*BoltDB) IsVerified ¶
IsVerified checks if user verified
func (BoltDB) List ¶
List returns list of all commented posts with counters uses count bucket to get number of comments
func (*BoltDB) SetBlock ¶
SetBlock blocks/unblocks user for given site. ttl defines for for how long, 0 - permanent block uses blocksBucketName with key=userID and val=TTL+now
func (*BoltDB) SetReadOnly ¶
SetReadOnly makes post read-only or reset the ro flag
func (*BoltDB) SetVerified ¶
SetVerified makes user verified or reset the flag
func (*BoltDB) User ¶
User extracts all comments for given site and given userID "users" bucket has sub-bucket for each userID, and keeps it as ts:ref
type BoltSite ¶
type BoltSite struct { FileName string // full path to boltdb SiteID string // ID to access given site }
BoltSite defines single site param
type Mongo ¶
type Mongo struct {
// contains filtered or unexported fields
}
Mongo implements engine interface
func NewMongo ¶
NewMongo makes mongo engine. bufferSize denies how many records will be buffered, 0 turns buffering off. flushDuration triggers automatic flus (write from buffer), 0 disables it and will flush as buffer size reached. important! don't use flushDuration=0 for production use as it can leave records in-fly state for long or even unlimited time.
func (*Mongo) Blocked ¶
func (m *Mongo) Blocked(siteID string) (users []store.BlockedUser, err error)
Blocked get lists of blocked users for given site
func (*Mongo) Delete ¶
Delete removes comment, by locator from the store. Posts collection only sets status to deleted and clear fields in order to prevent breaking trees of replies.
func (*Mongo) DeleteUser ¶
DeleteUser removes all comments for given user. Everything will be market as deleted and user name and userID will be changed to "deleted".
func (*Mongo) IsReadOnly ¶
IsReadOnly checks if post in RO
func (*Mongo) IsVerified ¶
IsVerified checks if user verified
func (*Mongo) SetBlock ¶
SetBlock blocks/unblocks user for given site. ttl defines for for how long, 0 - permanent block uses blocksBucketName with key=userID and val=TTL+now
func (*Mongo) SetReadOnly ¶
SetReadOnly makes post read-only or reset the ro flag
func (*Mongo) SetVerified ¶
SetVerified makes user verified or reset the flag