engine

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

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

Enum of all flags

View Source
const (
	// UserEmail is a user email
	UserEmail = UserDetail("email")
	// UserTelegram is a user telegram
	UserTelegram = UserDetail("telegram")
	// AllUserDetails used for listing and deletion requests
	AllUserDetails = UserDetail("all")
)

All possible user details

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 6 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
  • users details in "user_details" bucket. Key is userID, value - UserDetailEntry
  • 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), user, comment, user details, or everything

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

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

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

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

Update for locator.URL with mutable part of comment

func (*BoltDB) UserDetail

func (b *BoltDB) UserDetail(req UserDetailRequest) ([]UserDetailEntry, error)

UserDetail sets or gets single detail value, or gets all details for requested site. UserDetail returns list even for single entry request is a compromise in order to have both single detail getting and setting and all site's details listing under the same function (and not to extend interface by two separate functions).

type BoltSite

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

BoltSite defines single site param

type DeleteRequest

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"`
	UserDetail UserDetail       `json:"user_detail,omitempty"`
	DeleteMode store.DeleteMode `json:"del_mode"`
}

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

type FindRequest

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

type Flag string

Flag defines type of binary attribute

type FlagRequest

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

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

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

GetRequest is the input for Get func

type InfoRequest

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), user, comment, user details, or everything
	Flag(req FlagRequest) (bool, error)                         // set and get flags
	ListFlags(req FlagRequest) ([]interface{}, error)           // get list of flagged keys, like blocked & verified user

	// UserDetail sets or gets single detail value, or gets all details for requested site
	// Returns list even for single entry request is a compromise in order to have both single detail getting and setting
	// and all site's details listing under the same function (and not to extend interface by two separate functions)
	UserDetail(req UserDetailRequest) ([]UserDetailEntry, error)

	Close() error // close storage engine
}

Interface defines methods provided by low-level storage engine

type InterfaceMock added in v1.11.0

type InterfaceMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func() error

	// CountFunc mocks the Count method.
	CountFunc func(req FindRequest) (int, error)

	// CreateFunc mocks the Create method.
	CreateFunc func(comment store.Comment) (string, error)

	// DeleteFunc mocks the Delete method.
	DeleteFunc func(req DeleteRequest) error

	// FindFunc mocks the Find method.
	FindFunc func(req FindRequest) ([]store.Comment, error)

	// FlagFunc mocks the Flag method.
	FlagFunc func(req FlagRequest) (bool, error)

	// GetFunc mocks the Get method.
	GetFunc func(req GetRequest) (store.Comment, error)

	// InfoFunc mocks the Info method.
	InfoFunc func(req InfoRequest) ([]store.PostInfo, error)

	// ListFlagsFunc mocks the ListFlags method.
	ListFlagsFunc func(req FlagRequest) ([]interface{}, error)

	// UpdateFunc mocks the Update method.
	UpdateFunc func(comment store.Comment) error

	// UserDetailFunc mocks the UserDetail method.
	UserDetailFunc func(req UserDetailRequest) ([]UserDetailEntry, error)
	// contains filtered or unexported fields
}

InterfaceMock is a mock implementation of Interface.

func TestSomethingThatUsesInterface(t *testing.T) {

	// make and configure a mocked Interface
	mockedInterface := &InterfaceMock{
		CloseFunc: func() error {
			panic("mock out the Close method")
		},
		CountFunc: func(req FindRequest) (int, error) {
			panic("mock out the Count method")
		},
		CreateFunc: func(comment store.Comment) (string, error) {
			panic("mock out the Create method")
		},
		DeleteFunc: func(req DeleteRequest) error {
			panic("mock out the Delete method")
		},
		FindFunc: func(req FindRequest) ([]store.Comment, error) {
			panic("mock out the Find method")
		},
		FlagFunc: func(req FlagRequest) (bool, error) {
			panic("mock out the Flag method")
		},
		GetFunc: func(req GetRequest) (store.Comment, error) {
			panic("mock out the Get method")
		},
		InfoFunc: func(req InfoRequest) ([]store.PostInfo, error) {
			panic("mock out the Info method")
		},
		ListFlagsFunc: func(req FlagRequest) ([]interface{}, error) {
			panic("mock out the ListFlags method")
		},
		UpdateFunc: func(comment store.Comment) error {
			panic("mock out the Update method")
		},
		UserDetailFunc: func(req UserDetailRequest) ([]UserDetailEntry, error) {
			panic("mock out the UserDetail method")
		},
	}

	// use mockedInterface in code that requires Interface
	// and then make assertions.

}

func (*InterfaceMock) Close added in v1.11.0

func (mock *InterfaceMock) Close() error

Close calls CloseFunc.

func (*InterfaceMock) CloseCalls added in v1.11.0

func (mock *InterfaceMock) CloseCalls() []struct {
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedInterface.CloseCalls())

func (*InterfaceMock) Count added in v1.11.0

func (mock *InterfaceMock) Count(req FindRequest) (int, error)

Count calls CountFunc.

func (*InterfaceMock) CountCalls added in v1.11.0

func (mock *InterfaceMock) CountCalls() []struct {
	Req FindRequest
}

CountCalls gets all the calls that were made to Count. Check the length with:

len(mockedInterface.CountCalls())

func (*InterfaceMock) Create added in v1.11.0

func (mock *InterfaceMock) Create(comment store.Comment) (string, error)

Create calls CreateFunc.

func (*InterfaceMock) CreateCalls added in v1.11.0

func (mock *InterfaceMock) CreateCalls() []struct {
	Comment store.Comment
}

CreateCalls gets all the calls that were made to Create. Check the length with:

len(mockedInterface.CreateCalls())

func (*InterfaceMock) Delete added in v1.11.0

func (mock *InterfaceMock) Delete(req DeleteRequest) error

Delete calls DeleteFunc.

func (*InterfaceMock) DeleteCalls added in v1.11.0

func (mock *InterfaceMock) DeleteCalls() []struct {
	Req DeleteRequest
}

DeleteCalls gets all the calls that were made to Delete. Check the length with:

len(mockedInterface.DeleteCalls())

func (*InterfaceMock) Find added in v1.11.0

func (mock *InterfaceMock) Find(req FindRequest) ([]store.Comment, error)

Find calls FindFunc.

func (*InterfaceMock) FindCalls added in v1.11.0

func (mock *InterfaceMock) FindCalls() []struct {
	Req FindRequest
}

FindCalls gets all the calls that were made to Find. Check the length with:

len(mockedInterface.FindCalls())

func (*InterfaceMock) Flag added in v1.11.0

func (mock *InterfaceMock) Flag(req FlagRequest) (bool, error)

Flag calls FlagFunc.

func (*InterfaceMock) FlagCalls added in v1.11.0

func (mock *InterfaceMock) FlagCalls() []struct {
	Req FlagRequest
}

FlagCalls gets all the calls that were made to Flag. Check the length with:

len(mockedInterface.FlagCalls())

func (*InterfaceMock) Get added in v1.11.0

func (mock *InterfaceMock) Get(req GetRequest) (store.Comment, error)

Get calls GetFunc.

func (*InterfaceMock) GetCalls added in v1.11.0

func (mock *InterfaceMock) GetCalls() []struct {
	Req GetRequest
}

GetCalls gets all the calls that were made to Get. Check the length with:

len(mockedInterface.GetCalls())

func (*InterfaceMock) Info added in v1.11.0

func (mock *InterfaceMock) Info(req InfoRequest) ([]store.PostInfo, error)

Info calls InfoFunc.

func (*InterfaceMock) InfoCalls added in v1.11.0

func (mock *InterfaceMock) InfoCalls() []struct {
	Req InfoRequest
}

InfoCalls gets all the calls that were made to Info. Check the length with:

len(mockedInterface.InfoCalls())

func (*InterfaceMock) ListFlags added in v1.11.0

func (mock *InterfaceMock) ListFlags(req FlagRequest) ([]interface{}, error)

ListFlags calls ListFlagsFunc.

func (*InterfaceMock) ListFlagsCalls added in v1.11.0

func (mock *InterfaceMock) ListFlagsCalls() []struct {
	Req FlagRequest
}

ListFlagsCalls gets all the calls that were made to ListFlags. Check the length with:

len(mockedInterface.ListFlagsCalls())

func (*InterfaceMock) Update added in v1.11.0

func (mock *InterfaceMock) Update(comment store.Comment) error

Update calls UpdateFunc.

func (*InterfaceMock) UpdateCalls added in v1.11.0

func (mock *InterfaceMock) UpdateCalls() []struct {
	Comment store.Comment
}

UpdateCalls gets all the calls that were made to Update. Check the length with:

len(mockedInterface.UpdateCalls())

func (*InterfaceMock) UserDetail added in v1.11.0

func (mock *InterfaceMock) UserDetail(req UserDetailRequest) ([]UserDetailEntry, error)

UserDetail calls UserDetailFunc.

func (*InterfaceMock) UserDetailCalls added in v1.11.0

func (mock *InterfaceMock) UserDetailCalls() []struct {
	Req UserDetailRequest
}

UserDetailCalls gets all the calls that were made to UserDetail. Check the length with:

len(mockedInterface.UserDetailCalls())

type RPC

type RPC struct {
	jrpc.Client
}

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

func (*RPC) Close

func (r *RPC) Close() error

Close storage engine

func (*RPC) Count

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

Count gets comments count by user or site

func (*RPC) Create

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

Create comment and return ID

func (*RPC) Delete

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

Delete post(s), user, comment, user details, or everything

func (*RPC) Find

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

Find comments for locator

func (*RPC) Flag

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

Flag sets and gets flags

func (*RPC) Get

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

Get comment by ID

func (*RPC) Info

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

Info returns post(s) meta info

func (*RPC) ListFlags

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

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

func (*RPC) Update

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

Update comment, mutable parts only

func (*RPC) UserDetail

func (r *RPC) UserDetail(req UserDetailRequest) (result []UserDetailEntry, err error)

UserDetail sets or gets single detail value, or gets all details for requested site. UserDetail returns list even for single entry request is a compromise in order to have both single detail getting and setting and all site's details listing under the same function (and not to extend interface by two separate functions).

type UserDetail

type UserDetail string

UserDetail defines name of the user detail

type UserDetailEntry

type UserDetailEntry struct {
	UserID   string `json:"user_id"`            // duplicate user's id to use this structure not only embedded but separately
	Email    string `json:"email,omitempty"`    // UserEmail
	Telegram string `json:"telegram,omitempty"` // UserTelegram
}

UserDetailEntry contains single user details entry

type UserDetailRequest

type UserDetailRequest struct {
	Detail  UserDetail    `json:"detail"`           // detail name
	Locator store.Locator `json:"locator"`          // post locator
	UserID  string        `json:"user_id"`          // user id for get\set
	Update  string        `json:"update,omitempty"` // update value
}

UserDetailRequest is the input for both get/set for details, like email

Jump to

Keyboard shortcuts

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