urlstore

package
v0.0.0-...-2d1dec7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2018 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package urlstore containse the core engine of distill

Package urlstore provides the main functionalities for distill

Index

Constants

This section is empty.

Variables

View Source
var (
	// ColferSizeMax is the upper limit for serial byte sizes.
	ColferSizeMax = 16 * 1024 * 1024
)

Colfer configuration attributes

View Source
var ErrInvalidBackupRecord = fmt.Errorf("Invalid backup record")

ErrInvalidBackupRecord when a csv record from backup is different from expected

View Source
var ErrURLExpired = fmt.Errorf("url expired")

ErrURLExpired when url is expired

Functions

func Backup

func Backup(outFile string) (err error)

Backup the database as csv

func CloseSession

func CloseSession()

CloseSession closes the underling storage

func Delete

func Delete(id string) (err error)

Delete deletes an url

func DeleteURL

func DeleteURL(id string) (err error)

DeleteURL delete a url mapping

func GenerateDefaultConfig

func GenerateDefaultConfig(outFile, version string)

GenerateDefaultConfig generate a default configuration file an writes it in the outFile

func GetURLRedirect

func GetURLRedirect(id string) (redirectURL string, err error)

GetURLRedirect retrieve the redicrect url associated to an id it also fire an event of tipe opcodeGet

func ImportCSV

func ImportCSV(inFile string) (rows int, err error)

ImportCSV import urls from a csv file

func Insert

func Insert(u *URLInfo) (err error)

Insert an url into the the urlstore

func LoadStats

func LoadStats() (err error)

LoadStats write the URL's statistics

func NewSession

func NewSession()

NewSession opens the underling storage

func ResetStats

func ResetStats() (err error)

ResetStats reset global statistcs

func Restore

func Restore(inFile string) (count int, err error)

Restore the database from a backup file

func SaveStats

func SaveStats() (err error)

SaveStats write the URL's statistics

func UpdateStats

func UpdateStats(s Statistics)

UpdateStats uppdate urls statistics

func Upsert

func Upsert(u *URLInfo) (err error)

Upsert an url into the the urlstore

func UpsertURL

func UpsertURL(url *URLReq, forceAlphabet, forceLength bool, boundAt time.Time) (id string, err error)

UpsertURL insert or udpdate a url mapping

func UpsertURLSimple

func UpsertURLSimple(url *URLReq) (id string, err error)

UpsertURLSimple insert or updae an url shortcut for UpsertURL(true, true, time.Now())

Types

type BinSerializable

type BinSerializable interface {
	MarshalBinary() (data []byte, err error)
	UnmarshalBinary(data []byte) error
}

BinSerializable interface for binary serializable structs

type CSVSerializable

type CSVSerializable interface {
	MarshalRecord() (data []string, err error)
	UnmarshalRecord(data []string) error
}

CSVSerializable interface for binary serializable structs

type ColferError

type ColferError int

ColferError signals a data mismatch as as a byte index.

func (ColferError) Error

func (i ColferError) Error() string

Error honors the error interface.

type ColferMax

type ColferMax string

ColferMax signals an upper limit breach.

func (ColferMax) Error

func (m ColferMax) Error() string

Error honors the error interface.

type ColferTail

type ColferTail int

ColferTail signals data continuation as a byte index.

func (ColferTail) Error

func (i ColferTail) Error() string

Error honors the error interface.

type ConfigSchema

type ConfigSchema struct {
	Server  ServerConfig  `yaml:"server"`
	ShortID ShortIDConfig `yaml:"shortId"`
	Tuning  TuningConfig  `yaml:"tuning"`
}

ConfigSchema define the configuration object

var Config ConfigSchema

Config system configuration

func (*ConfigSchema) Defaults

func (c *ConfigSchema) Defaults()

Defaults generate configuration defaults

func (*ConfigSchema) Validate

func (c *ConfigSchema) Validate()

Validate configuration

type ServerConfig

type ServerConfig struct {
	APIKey          string `yaml:"apiKey"`
	Host            string `yaml:"host"`
	Port            int    `yaml:"port"`
	DbPath          string `yaml:"dbPath"`
	RootRedirect    string `yaml:"rootRedirect"`
	ExpiredRedirect string `yaml:"expiredRedirect"`
}

ServerConfig configuration for the server

type ShortID

type ShortID struct {
	ID string `json:"id"`
}

ShortID used in reply and channel comunication

func (*ShortID) Bind

func (u *ShortID) Bind(r *http.Request) error

Bind will run after the unmarshalling is complete

type ShortIDConfig

type ShortIDConfig struct {
	Alphabet    string    `yaml:"alphabet"`
	Length      int       `yaml:"length"`
	MaxRequests int64     `yaml:"maxRequests"`
	TTL         int64     `yaml:"ttl"`
	ExpireOn    time.Time `yaml:"expireOn"`
}

ShortIDConfig configureaiont for the short id

type Statistics

type Statistics struct {
	Urls    int64 `json:"urls"`
	Gets    int64 `json:"gets"`
	Upserts int64 `json:"upserts"`
	Deletes int64 `json:"deletes"`
}

Statistics contains the global statistics

func GetStats

func GetStats() (s *Statistics)

GetStats get the statistics

func (*Statistics) String

func (s *Statistics) String() string

type TuningConfig

type TuningConfig struct {
	StatsEventsWorkerNum   int     `yaml:"statsEventsWorkerNum"`
	StatsCaheSize          int     `yaml:"statsCacheSize"`
	DbPurgeWritesCount     int     `yaml:"dbPurgeWritesCount"`
	DbGCDeletesCount       int     `yaml:"dbGCDeletesCount"`
	DbGCDiscardRation      float64 `yaml:"dbGCDiscardRation"`
	URLCaheSize            int     `yaml:"URLCaheSize"`
	BckCSVIterPrefetchSize int     `yaml:"exportIteratorPrefetchSize"`
	APIKeyHeaderName       string  `yaml:"apiKeyHeaderName"`
}

TuningConfig fine tuning configuration

type URLInfo

type URLInfo struct {
	ID string

	URL string

	Counter int64

	BountAt time.Time

	TTL int64

	MaxRequests int64

	ExpireOn time.Time
}

URLInfo contains the data associated to an id

func Get

func Get(id string) (u *URLInfo, err error)

Get an url from the datastore

func GetURLInfo

func GetURLInfo(id string) (urlInfo *URLInfo, err error)

GetURLInfo retrieve the url info associated to an id

func Peek

func Peek(id string) (u *URLInfo, err error)

Peek retrive a url without incrementing the counter

func (URLInfo) ExpirationDate

func (u URLInfo) ExpirationDate() time.Time

ExpirationDate return the expiration date of the URLInfo

func (*URLInfo) MarshalBinary

func (o *URLInfo) MarshalBinary() (data []byte, err error)

MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is distill.ColferMax.

func (*URLInfo) MarshalLen

func (o *URLInfo) MarshalLen() (int, error)

MarshalLen returns the Colfer serial byte size. The error return option is distill.ColferMax.

func (*URLInfo) MarshalRecord

func (u *URLInfo) MarshalRecord() []string

MarshalRecord marshal a urlinfo to a string array (for csv)

func (*URLInfo) MarshalTo

func (o *URLInfo) MarshalTo(buf []byte) int

MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.

func (URLInfo) String

func (u URLInfo) String() string

String version of urlinfo

func (*URLInfo) Unmarshal

func (o *URLInfo) Unmarshal(data []byte) (int, error)

Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, distill.ColferError adistillistill.ColferMax.

func (*URLInfo) UnmarshalBinary

func (o *URLInfo) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, distill.ColferErrodistillistill.ColferTaidistilld distill.ColferMax.

func (*URLInfo) UnmarshalRecord

func (u *URLInfo) UnmarshalRecord(pieces []string) (err error)

UnmarshalRecord unmarshal a string array into a urlinfo

type URLIterator

type URLIterator struct {
	Transaction *badger.Txn
	Iterator    *badger.Iterator
	KeyPrefix   []byte
}

URLIterator an iterator over URLs

func NewURLIterator

func NewURLIterator() *URLIterator

NewURLIterator return an url iterator over the database

func (*URLIterator) Close

func (i *URLIterator) Close()

Close the iterator

func (*URLIterator) HasNext

func (i *URLIterator) HasNext() bool

HasNext tells if there are still elements in the list

func (*URLIterator) NextURL

func (i *URLIterator) NextURL() (u *URLInfo, err error)

NextURL get the next URL from the iterator

type URLOp

type URLOp struct {
	ID string
	// contains filtered or unexported fields
}

URLOp to track events on urls

type URLReq

type URLReq struct {
	ID          string    `json:"id"`
	URL         string    `json:"url"`
	MaxRequests int64     `json:"max_requests,omitempty"`
	TTL         int64     `json:"ttl,omitempty"`
	ExpireOn    time.Time `json:"expire_on,omitempty"`
}

URLReq request from a client to register an url

func (*URLReq) Bind

func (u *URLReq) Bind(r *http.Request) error

Bind will run after the unmarshalling is complete

func (*URLReq) UnmarshalRecord

func (u *URLReq) UnmarshalRecord(pieces []string) (err error)

UnmarshalRecord unmarshal a string array (csv record) to URLReq pointer

Jump to

Keyboard shortcuts

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