record

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2016 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Alive counts records that are not removed.
	Alive = 1
	//Removed counts records that are  removed.
	Removed = 2
	//All counts all records
	All = 3
)

Variables

This section is empty.

Functions

func ForEach added in v0.2.0

func ForEach(tx *bolt.Tx, cond func([]byte, int) bool, eachDo func(*DB) error) error

ForEach do eachDo for each k/v to "record" db.

func ParseHeadResponse

func ParseHeadResponse(res []string, datfile string) map[string]*Head

ParseHeadResponse parses response of head and returns Head map.

Types

type DB added in v0.2.0

type DB struct {
	*Head
	Body    string
	Deleted bool
}

DB represents one record in db.

func GetFromDB added in v0.2.0

func GetFromDB(tx *bolt.Tx, h *Head) (*DB, error)

GetFromDB gets DB db.

func GetFromDBs added in v0.2.0

func GetFromDBs(tx *bolt.Tx, datfile string) ([]*DB, error)

GetFromDBs gets DBs whose thread name is datfile.

func (*DB) Del added in v0.2.0

func (d *DB) Del(tx *bolt.Tx)

Del deletes data from db.

func (*DB) Put added in v0.2.0

func (d *DB) Put(tx *bolt.Tx) error

Put puts this one to db.

type Head struct {
	Datfile string //cache file name
	Stamp   int64  //unixtime
	ID      string //md5(bodystr)
}

Head represents one line in updatelist/recentlist

func (*Head) Exists

func (u *Head) Exists() bool

Exists return true if record file exists.

func (*Head) Hash

func (u *Head) Hash() [16]byte

Hash returns md5 of Head.

func (*Head) Idstr

func (u *Head) Idstr() string

Idstr returns real file name of the record file.

func (*Head) Recstr

func (u *Head) Recstr() string

Recstr returns one line of update/recentlist file.

func (*Head) Remove

func (u *Head) Remove() error

Remove moves the record file to remove path

func (*Head) ToKey added in v0.2.0

func (u *Head) ToKey() []byte

ToKey returns key for db.

type Map

type Map map[string]*Record

Map is a map key=stamp_id, value=record.

func FromRecordDB

func FromRecordDB(datfile string, kind int) (Map, error)

FromRecordDB makes record map from record db.

func (Map) Get

func (r Map) Get(i string, def *Record) *Record

Get returns records which hav key=i. return def if not found.

func (Map) Keys

func (r Map) Keys() []string

Keys returns key strings(ids) of records

type Record

type Record struct {
	*Head
	// contains filtered or unexported fields
}

Record represents one record.

func Make

func Make(line string) (*Record, error)

Make makes and returns record from Recstr

func New

func New(datfile, id string, stamp int64) *Record

New makes Record struct.

func NewIDstr

func NewIDstr(datfile, idstr string) (*Record, error)

NewIDstr parse idstr unixtime+"_"+md5(bodystr)), set stamp and id, and return record obj. if parse failes returns nil.

func (*Record) AttachPath

func (r *Record) AttachPath(thumbnailSize string) string

AttachPath returns attach path by creating path from args.

func (*Record) Build

func (r *Record) Build(stamp int64, body map[string]string, passwd string) string

Build sets params in record from args and return id.

func (*Record) CheckData

func (r *Record) CheckData(begin, end int64) error

CheckData makes records from res and checks its records meets condisions of args. adds the rec to cache if meets conditions. if spam or big data, remove the rec from disk. returns count of added records to the cache and spam/getting error.

func (*Record) CopyHead

func (r *Record) CopyHead() Head

CopyHead copies and returns Head.

func (*Record) GetBodyValue

func (r *Record) GetBodyValue(k string, def string) string

GetBodyValue returns value of key k return def if not exists.

func (*Record) GetData

func (r *Record) GetData(n *node.Node) error

GetData gets records from node n and checks its is same as stamp and id in args. save recs if success. returns errSpam or errGet.

func (*Record) Getbody

func (r *Record) Getbody() string

Getbody retuns contents of rec after loading if needed. used in template

func (*Record) HasBodyValue

func (r *Record) HasBodyValue(k string) bool

HasBodyValue returns true if key k exists used in templates

func (*Record) InRange

func (r *Record) InRange(begin, end int64, id string) bool

InRange returns true if stamp is in begin~end and idstr has id.

func (*Record) IsSpam

func (r *Record) IsSpam() bool

IsSpam returns true if Recstr is listed in spam.txt

func (*Record) Load

func (r *Record) Load() error

Load loads a record file and parses it.

func (r *Record) MakeAttachLink(sakuHost string) string

MakeAttachLink makes and returns attached file link.

func (*Record) Meets added in v0.2.0

func (r *Record) Meets(begin, end int64) bool

Meets checks the record meets conditions of args

func (*Record) Parse

func (r *Record) Parse(recstr string) error

Parse parses one line in record file and response of /recent/ and set params to record r.

func (*Record) Recstr

func (r *Record) Recstr() string

Recstr returns one line in the record file.

func (*Record) ShortPubkey

func (r *Record) ShortPubkey() string

ShortPubkey returns short version of pubkey. used in templates

func (*Record) Sync

func (r *Record) Sync()

Sync saves Recstr to the file. if attached file exists, saves it to attached path. if signed, also saves body part.

func (*Record) SyncTX added in v0.2.0

func (r *Record) SyncTX(tx *bolt.Tx, deleted bool) error

SyncTX saves Recstr to the file. if attached file exists, saves it to attached path. if signed, also saves body part.

Jump to

Keyboard shortcuts

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