engine

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: MIT Imports: 13 Imported by: 22

Documentation

Overview

Code generated by mockery v1.0.0. DO NOT EDIT.

Index

Constants

View Source
const (
	ReadOnly = Flag("readonly")
	Verified = Flag("verified")
	Blocked  = Flag("blocked")
)

Enum of all flags

Variables

This section is empty.

Functions

func SortComments

func SortComments(comments []store.Comment, sortFld string) []store.Comment

SortComments is for engines can't sort data internally

Types

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. For each site new boltdb file created

func (*BoltDB) Close

func (b *BoltDB) Close() error

Close boltdb store

func (*BoltDB) Count

func (b *BoltDB) Count(req FindRequest) (count int, err error)

Count returns number of comments for post or user

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(req DeleteRequest) error

Delete post(s) by id or by userID

func (*BoltDB) Find

func (b *BoltDB) Find(req FindRequest) (comments []store.Comment, err error)

Find returns all comments for given request and sorts results

func (*BoltDB) Flag added in v1.4.0

func (b *BoltDB) Flag(req FlagRequest) (val bool, err error)

Flag sets and gets flag values

func (*BoltDB) Get

func (b *BoltDB) Get(req GetRequest) (comment store.Comment, err error)

Get returns comment for locator.URL and commentID string

func (*BoltDB) Info

func (b *BoltDB) Info(req InfoRequest) ([]store.PostInfo, error)

Info get post(s) meta info

func (*BoltDB) ListFlags added in v1.4.0

func (b *BoltDB) ListFlags(req FlagRequest) (res []interface{}, err error)

ListFlags get list of flagged keys, like blocked & verified user works for full locator (post flags) or with userID

func (*BoltDB) Update added in v1.4.0

func (b *BoltDB) Update(comment store.Comment) error

Update for locator.URL with mutable part of comment

type BoltSite

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

BoltSite defines single site param

type DeleteRequest added in v1.4.0

type DeleteRequest struct {
	Locator    store.Locator    `json:"locator"` // lack of URL means site operation
	CommentID  string           `json:"comment_id,omitempty"`
	UserID     string           `json:"user_id,omitempty"`
	DeleteMode store.DeleteMode `json:"del_mode"`
}

DeleteRequest is the input for all delete operations (comments, sites, users)

type FindRequest added in v1.4.0

type FindRequest struct {
	Locator store.Locator `json:"locator"`           // lack of URL means site operation
	UserID  string        `json:"user_id,omitempty"` // presence of UserID treated as user-related find
	Sort    string        `json:"sort,omitempty"`    // sort order with +/-field syntax
	Since   time.Time     `json:"since,omitempty"`   // time limit for found results
	Limit   int           `json:"limit,omitempty"`
	Skip    int           `json:"skip,omitempty"`
}

FindRequest is the input for all find operations

type Flag added in v1.4.0

type Flag string

Flag defines type of binary attribute

type FlagRequest added in v1.4.0

type FlagRequest struct {
	Flag    Flag          `json:"flag"`              // flag type
	Locator store.Locator `json:"locator"`           // post locator
	UserID  string        `json:"user_id,omitempty"` // for flags setting user status
	Update  FlagStatus    `json:"update,omitempty"`  // if FlagNonSet it will be get op, if set will set the value
	TTL     time.Duration `json:"ttl,omitempty"`     // ttl for time-sensitive flags only, like blocked for some period
}

FlagRequest is the input for both get/set for flags, like blocked, verified and so on

type FlagStatus added in v1.4.0

type FlagStatus int

FlagStatus represents values of the flag update

const (
	FlagNonSet FlagStatus = 0
	FlagTrue   FlagStatus = 1
	FlagFalse  FlagStatus = -1
)

enum of update values

type GetRequest added in v1.4.0

type GetRequest struct {
	Locator   store.Locator `json:"locator"`
	CommentID string        `json:"comment_id"`
}

GetRequest is the input for Get func

type InfoRequest added in v1.4.0

type InfoRequest struct {
	Locator     store.Locator `json:"locator"`
	Limit       int           `json:"limit,omitempty"`
	Skip        int           `json:"skip,omitempty"`
	ReadOnlyAge int           `json:"ro_age,omitempty"`
}

InfoRequest is the input of Info operation used to get meta data about posts

type Interface

type Interface interface {
	Create(comment store.Comment) (commentID string, err error) // create new comment, avoid dups by id
	Update(comment store.Comment) error                         // update comment, mutable parts only
	Get(req GetRequest) (store.Comment, error)                  // get comment by id
	Find(req FindRequest) ([]store.Comment, error)              // find comments for locator or site
	Info(req InfoRequest) ([]store.PostInfo, error)             // get post(s) meta info
	Count(req FindRequest) (int, error)                         // get count for post or user
	Delete(req DeleteRequest) error                             // delete post(s) by id or by userID
	Flag(req FlagRequest) (bool, error)                         // set and get flags
	ListFlags(req FlagRequest) ([]interface{}, error)           // get list of flagged keys, like blocked & verified user
	Close() error                                               // close storage engine
}

Interface defines methods provided by low-level storage engine

type MockInterface added in v1.4.0

type MockInterface struct {
	mock.Mock
}

MockInterface is an autogenerated mock type for the Interface type

func (*MockInterface) Close added in v1.4.0

func (_m *MockInterface) Close() error

Close provides a mock function with given fields:

func (*MockInterface) Count added in v1.4.0

func (_m *MockInterface) Count(req FindRequest) (int, error)

Count provides a mock function with given fields: req

func (*MockInterface) Create added in v1.4.0

func (_m *MockInterface) Create(comment store.Comment) (string, error)

Create provides a mock function with given fields: comment

func (*MockInterface) Delete added in v1.4.0

func (_m *MockInterface) Delete(req DeleteRequest) error

Delete provides a mock function with given fields: req

func (*MockInterface) Find added in v1.4.0

func (_m *MockInterface) Find(req FindRequest) ([]store.Comment, error)

Find provides a mock function with given fields: req

func (*MockInterface) Flag added in v1.4.0

func (_m *MockInterface) Flag(req FlagRequest) (bool, error)

Flag provides a mock function with given fields: req

func (*MockInterface) Get added in v1.4.0

func (_m *MockInterface) Get(req GetRequest) (store.Comment, error)

Get provides a mock function with given fields: req

func (*MockInterface) Info added in v1.4.0

func (_m *MockInterface) Info(req InfoRequest) ([]store.PostInfo, error)

Info provides a mock function with given fields: req

func (*MockInterface) ListFlags added in v1.4.0

func (_m *MockInterface) ListFlags(req FlagRequest) ([]interface{}, error)

ListFlags provides a mock function with given fields: req

func (*MockInterface) Update added in v1.4.0

func (_m *MockInterface) Update(comment store.Comment) error

Update provides a mock function with given fields: comment

type RPC added in v1.4.0

type RPC struct {
	rpc.Client
}

RPC implements remote engine and delegates all Calls to remote http server

func (*RPC) Close added in v1.4.0

func (r *RPC) Close() error

Close storage engine

func (*RPC) Count added in v1.4.0

func (r *RPC) Count(req FindRequest) (count int, err error)

Count gets comments count by user or site

func (*RPC) Create added in v1.4.0

func (r *RPC) Create(comment store.Comment) (commentID string, err error)

Create comment and return ID

func (*RPC) Delete added in v1.4.0

func (r *RPC) Delete(req DeleteRequest) error

Delete post(s) by id or by userID

func (*RPC) Find added in v1.4.0

func (r *RPC) Find(req FindRequest) (comments []store.Comment, err error)

Find comments for locator

func (*RPC) Flag added in v1.4.0

func (r *RPC) Flag(req FlagRequest) (status bool, err error)

Flag sets and gets flags

func (*RPC) Get added in v1.4.0

func (r *RPC) Get(req GetRequest) (comment store.Comment, err error)

Get comment by ID

func (*RPC) Info added in v1.4.0

func (r *RPC) Info(req InfoRequest) (info []store.PostInfo, err error)

Info returns post(s) meta info

func (*RPC) ListFlags added in v1.4.0

func (r *RPC) ListFlags(req FlagRequest) (list []interface{}, err error)

ListFlags get list of flagged keys, like blocked & verified user

func (*RPC) Update added in v1.4.0

func (r *RPC) Update(comment store.Comment) error

Update comment, mutable parts only

Jump to

Keyboard shortcuts

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