Documentation
¶
Overview ¶
Package urlstore contains the engine of distill
Package urlstore provides the main functionalities for distill
Index ¶
- Variables
- func Backup(outFile string) (err error)
- func CloseSession()
- func Defaults()
- func Delete(id string) (err error)
- func DeleteURL(id string) (err error)
- func GenerateDefaultConfig(outFile, version string)
- func GetURLRedirect(id string) (redirectURL string, err error)
- func ImportCSV(inFile string) (rows int, err error)
- func Insert(u *URLInfo) (err error)
- func LoadStats() (err error)
- func NewSession()
- func ResetStats() (err error)
- func Restore(inFile string) (count int, err error)
- func SaveStats() (err error)
- func UpdateStats(s Statistics)
- func Upsert(u *URLInfo) (err error)
- func UpsertURL(url *URLReq, forceAlphabet, forceLength bool, boundAt time.Time) (id string, err error)
- func UpsertURLSimple(url *URLReq) (id string, err error)
- type BinSerializable
- type CSVSerializable
- type ColferError
- type ColferMax
- type ColferTail
- type ConfigSchema
- type ServerConfig
- type ShortID
- type ShortIDConfig
- type Statistics
- type TuningConfig
- type URLInfo
- func (u URLInfo) ExpirationDate() time.Time
- func (o *URLInfo) MarshalBinary() (data []byte, err error)
- func (o *URLInfo) MarshalLen() (int, error)
- func (u *URLInfo) MarshalRecord() []string
- func (o *URLInfo) MarshalTo(buf []byte) int
- func (u URLInfo) String() string
- func (o *URLInfo) Unmarshal(data []byte) (int, error)
- func (o *URLInfo) UnmarshalBinary(data []byte) error
- func (u *URLInfo) UnmarshalRecord(pieces []string) (err error)
- type URLIterator
- type URLOp
- type URLReq
Constants ¶
This section is empty.
Variables ¶
var (
// ColferSizeMax is the upper limit for serial byte sizes.
ColferSizeMax = 16 * 1024 * 1024
)
Colfer configuration attributes
var ErrInvalidBackupRecord = fmt.Errorf("Invalid backup record")
ErrInvalidBackupRecord when a csv record from backup is different from expected
var ErrURLExhausted = fmt.Errorf("url exhausted")
ErrURLExhausted when url is expired
var ErrURLExpired = fmt.Errorf("url expired")
ErrURLExpired when url is expired
Functions ¶
func GenerateDefaultConfig ¶
func GenerateDefaultConfig(outFile, version string)
GenerateDefaultConfig generate a default configuration file an writes it in the outFile
func GetURLRedirect ¶
GetURLRedirect retrieve the redicrect url associated to an id it also fire an event of tipe opcodeGet
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 ¶
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 ConfigSchema ¶
type ConfigSchema struct { Server ServerConfig `yaml:"server" mapstructure:"server"` ShortID ShortIDConfig `yaml:"short_id" mapstructure:"short_id"` Tuning TuningConfig `yaml:"tuning" mapstructure:"tuning"` }
ConfigSchema define the configuration object
var Config ConfigSchema
Config system configuration
func (*ConfigSchema) Defaults ¶
func (c *ConfigSchema) Defaults()
Defaults generate configuration defaults
type ServerConfig ¶
type ServerConfig struct { APIKey string `yaml:"api_key" mapstructure:"api_key"` Host string `yaml:"host" mapstructure:"host"` Port int `yaml:"port" mapstructure:"port"` DbPath string `yaml:"db_path" mapstructure:"db_path"` }
ServerConfig configuration for the server
type ShortID ¶
type ShortID struct {
ID string `json:"id"`
}
ShortID used in reply and channel comunication
type ShortIDConfig ¶
type ShortIDConfig struct { Alphabet string `yaml:"alphabet" mapstructure:"alphabet"` Length int `yaml:"length" mapstructure:"length"` MaxRequests uint64 `yaml:"max_requests" mapstructure:"max_requests"` TTL uint64 `yaml:"ttl" mapstructure:"ttl"` ExpireOn time.Time `yaml:"expire_on" mapstructure:"expire_on"` RootRedirectURL string `yaml:"root_redirect_url" mapstructure:"root_redirect_url"` ExpiredRedirectURL string `yaml:"expired_redirect_url" mapstructure:"expired_redirect_url"` ExhaustedRedirectURL string `yaml:"exhausted_redirect_url" mapstructure:"exhausted_redirect_url"` }
ShortIDConfig configuration for the short id
type Statistics ¶
type Statistics struct { Urls uint64 `json:"urls"` Gets uint64 `json:"gets"` GetsExpired uint64 `json:"gets_expired"` Upserts uint64 `json:"upserts"` Deletes uint64 `json:"deletes"` LastRequest time.Time `json:"last_request"` }
Statistics contains the global statistics
func (*Statistics) String ¶
func (s *Statistics) String() string
type TuningConfig ¶
type TuningConfig struct { StatsEventsWorkerNum int `yaml:"stats_events_worker_num" mapstructure:"stats_events_worker_num"` StatsCacheSize int `yaml:"stats_cache_size" mapstructure:"stats_cache_size"` DbPurgeWritesCount uint64 `yaml:"db_purge_writes_count" mapstructure:"db_purge_writes_count"` DbGCDeletesCount uint64 `yaml:"db_gc_deletes_count" mapstructure:"db_gc_deletes_count"` DbGCDiscardRation float64 `yaml:"db_gc_discard_ration" mapstructure:"db_gc_discard_ration"` URLCacheSize int `yaml:"url_cache_size" mapstructure:"url_cache_size"` BckCSVIterPrefetchSize int `yaml:"export_iterator_prefetch_size" mapstructure:"export_iterator_prefetch_size"` APIKeyHeaderName string `yaml:"api_key_header_name" mapstructure:"api_key_header_name"` }
TuningConfig fine tuning configuration
type URLInfo ¶
type URLInfo struct { ID string URL string Counter uint64 BountAt time.Time MaxRequests uint64 ExhaustedURL string TTL uint64 ExpireOn time.Time ExpiredURL string }
URLInfo contains the data associated to an id
func GetURLInfo ¶
GetURLInfo retrieve the url info associated to an id
func (URLInfo) ExpirationDate ¶
ExpirationDate return the expiration date of the URLInfo
func (*URLInfo) MarshalBinary ¶
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is urlstore.ColferMax.
func (*URLInfo) MarshalLen ¶
MarshalLen returns the Colfer serial byte size. The error return option is urlstore.ColferMax.
func (*URLInfo) MarshalRecord ¶
MarshalRecord marshal a urlinfo to a string array (for csv)
func (*URLInfo) MarshalTo ¶
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) Unmarshal ¶
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, urlstore.ColferError and urlstore.ColferMax.
func (*URLInfo) UnmarshalBinary ¶
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, urlstore.ColferError, urlstore.ColferTail and urlstore.ColferMax.
func (*URLInfo) UnmarshalRecord ¶
UnmarshalRecord unmarshal a string array into a urlinfo
type URLIterator ¶
URLIterator an iterator over URLs
func NewURLIterator ¶
func NewURLIterator() *URLIterator
NewURLIterator return an url iterator over the database
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 uint64 `json:"max_requests,omitempty"` ExhaustedURL string `json:"url_exhausted"` TTL uint64 `json:"ttl,omitempty"` ExpireOn time.Time `json:"expire_on,omitempty"` ExpiredURL string `json:"url_expired"` }
URLReq request from a client to register an url
func (*URLReq) UnmarshalRecord ¶
UnmarshalRecord unmarshal a string array (csv record) to URLReq pointer