Documentation
¶
Overview ¶
Package urlstore containse the core engine of distill
Package urlstore provides the main functionalities for distill
Index ¶
- Variables
- func Backup(outFile string) (err error)
- func CloseSession()
- 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 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"` 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
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
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 (*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 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 distill.ColferMax.
func (*URLInfo) MarshalLen ¶
MarshalLen returns the Colfer serial byte size. The error return option is distill.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, distill.ColferError adistillistill.ColferMax.
func (*URLInfo) UnmarshalBinary ¶
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, distill.ColferErrodistillistill.ColferTaidistilld distill.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 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) UnmarshalRecord ¶
UnmarshalRecord unmarshal a string array (csv record) to URLReq pointer