engine

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package engine defines interfaces each supported storage should implement. Includes default implementation with boltdb

Index

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 NewBoltDB

func NewBoltDB(options bolt.Options, sites ...BoltSite) (*BoltDB, error)

NewBoltDB makes persistent boltdb-based store

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) Close

func (b *BoltDB) Close() error

Close boltdb store

func (*BoltDB) Count

func (b *BoltDB) Count(locator store.Locator) (count int, err error)

Count returns number of comments for locator

func (*BoltDB) Create

func (b *BoltDB) Create(comment store.Comment) (commentID string, err error)

Create saves new comment to store. Adds to posts bucket, reference to last and user bucket and increments count bucket

func (*BoltDB) Delete

func (b *BoltDB) Delete(locator store.Locator, commentID string, mode store.DeleteMode) error

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) DeleteAll

func (b *BoltDB) DeleteAll(siteID string) error

DeleteAll removes all top-level buckets for given siteID

func (*BoltDB) DeleteUser

func (b *BoltDB) DeleteUser(siteID string, userID string) error

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) Find

func (b *BoltDB) Find(locator store.Locator, sortFld string) (comments []store.Comment, err error)

Find returns all comments for post and sorts results

func (*BoltDB) Get

func (b *BoltDB) Get(locator store.Locator, commentID string) (comment store.Comment, err error)

Get returns comment for locator.URL and commentID string

func (*BoltDB) Info

func (b *BoltDB) Info(locator store.Locator, readOnlyAge int) (store.PostInfo, error)

Info returns time range and count for locator

func (*BoltDB) IsBlocked

func (b *BoltDB) IsBlocked(siteID string, userID string) (blocked bool)

IsBlocked checks if user blocked

func (*BoltDB) IsReadOnly

func (b *BoltDB) IsReadOnly(locator store.Locator) (ro bool)

IsReadOnly checks if post in RO mode

func (*BoltDB) IsVerified

func (b *BoltDB) IsVerified(siteID string, userID string) (verified bool)

IsVerified checks if user verified

func (*BoltDB) Last

func (b *BoltDB) Last(siteID string, max int) (comments []store.Comment, err error)

Last returns up to max last comments for given siteID

func (BoltDB) List

func (b BoltDB) List(siteID string, limit, skip int) (list []store.PostInfo, err error)

List returns list of all commented posts with counters uses count bucket to get number of comments

func (*BoltDB) Put

func (b *BoltDB) Put(locator store.Locator, comment store.Comment) error

Put updates comment for locator.URL with mutable part of comment

func (*BoltDB) SetBlock

func (b *BoltDB) SetBlock(siteID string, userID string, status bool, ttl time.Duration) error

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

func (b *BoltDB) SetReadOnly(locator store.Locator, status bool) error

SetReadOnly makes post read-only or reset the ro flag

func (*BoltDB) SetVerified

func (b *BoltDB) SetVerified(siteID string, userID string, status bool) error

SetVerified makes user verified or reset the flag

func (*BoltDB) User

func (b *BoltDB) User(siteID, userID string, limit, skip int) (comments []store.Comment, err error)

User extracts all comments for given site and given userID "users" bucket has sub-bucket for each userID, and keeps it as ts:ref

func (*BoltDB) UserCount

func (b *BoltDB) UserCount(siteID, userID string) (int, error)

UserCount returns number of comments for user

func (*BoltDB) Verified

func (b *BoltDB) Verified(siteID string) (ids []string, err error)

Verified returns list of verified userIDs

type BoltSite

type BoltSite struct {
	FileName string // full path to boltdb
	SiteID   string // ID to access given site
}

BoltSite defines single site param

type Interface

type Interface interface {
	Accessor
	Admin
}

Interface combines all store interfaces

type Mongo

type Mongo struct {
	// contains filtered or unexported fields
}

Mongo implements engine interface

func NewMongo

func NewMongo(conn *mongo.Connection, bufferSize int, flushDuration time.Duration) (*Mongo, error)

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) Close

func (m *Mongo) Close() error

Close boltdb store

func (*Mongo) Count

func (m *Mongo) Count(locator store.Locator) (count int, err error)

Count returns number of comments for locator

func (*Mongo) Create

func (m *Mongo) Create(comment store.Comment) (commentID string, err error)

Create new comment, write can be buffered and delayed.

func (*Mongo) Delete

func (m *Mongo) Delete(locator store.Locator, commentID string, mode store.DeleteMode) error

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) DeleteAll

func (m *Mongo) DeleteAll(siteID string) error

DeleteAll removes all info about siteID

func (*Mongo) DeleteUser

func (m *Mongo) DeleteUser(siteID string, userID string) error

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) Find

func (m *Mongo) Find(locator store.Locator, sortFld string) (comments []store.Comment, err error)

Find returns all comments for post and sorts results

func (*Mongo) Get

func (m *Mongo) Get(locator store.Locator, commentID string) (comment store.Comment, err error)

Get returns comment for locator.URL and commentID string

func (*Mongo) Info

func (m *Mongo) Info(locator store.Locator, readOnlyAge int) (info store.PostInfo, err error)

Info returns time range and count for locator

func (*Mongo) IsBlocked

func (m *Mongo) IsBlocked(siteID string, userID string) (blocked bool)

IsBlocked checks if user blocked

func (*Mongo) IsReadOnly

func (m *Mongo) IsReadOnly(locator store.Locator) (ro bool)

IsReadOnly checks if post in RO

func (*Mongo) IsVerified

func (m *Mongo) IsVerified(siteID string, userID string) (verified bool)

IsVerified checks if user verified

func (*Mongo) Last

func (m *Mongo) Last(siteID string, max int) (comments []store.Comment, err error)

Last returns up to max last comments for given siteID

func (*Mongo) List

func (m *Mongo) List(siteID string, limit, skip int) (list []store.PostInfo, err error)

List returns list of all commented posts with counters

func (*Mongo) Put

func (m *Mongo) Put(locator store.Locator, comment store.Comment) error

Put updates comment for locator.URL with mutable part of comment

func (*Mongo) SetBlock

func (m *Mongo) SetBlock(siteID string, userID string, status bool, ttl time.Duration) error

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

func (m *Mongo) SetReadOnly(locator store.Locator, status bool) (err error)

SetReadOnly makes post read-only or reset the ro flag

func (*Mongo) SetVerified

func (m *Mongo) SetVerified(siteID string, userID string, status bool) error

SetVerified makes user verified or reset the flag

func (*Mongo) User

func (m *Mongo) User(siteID, userID string, limit, skip int) (comments []store.Comment, err error)

User extracts all comments for given site and given userID

func (*Mongo) UserCount

func (m *Mongo) UserCount(siteID, userID string) (count int, err error)

UserCount returns number of comments for user

func (*Mongo) Verified

func (m *Mongo) Verified(siteID string) (ids []string, err error)

Verified returns list of verified user IDs

type UserRequest

type UserRequest struct {
	SiteID string
	UserID string
	Limit  int
	Skip   int
}

UserRequest is the request send to get comments by user

Jump to

Keyboard shortcuts

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