Documentation ¶
Index ¶
- Constants
- func WithIDGenerator(idgen ids.Generator) func(*Slink)
- func WithMaxCreateAttempts(maxCreateAttempts int) func(*Slink)
- func WithStorage(storage storage.Storage) func(*Slink)
- type CreateInput
- type ErrCreateAttemptsExhausted
- type ErrInvalidLinkURL
- type ErrInvalidShortLinkID
- type Slink
- func (s *Slink) CreateShortLink(ctx context.Context, input *CreateInput) (*models.ShortLink, error)
- func (s *Slink) GetOrCreateShortLink(ctx context.Context, input *CreateInput) (*models.ShortLink, error)
- func (s *Slink) GetShortLinkByID(ctx context.Context, shortLinkID string) (*models.ShortLink, error)
- func (s *Slink) GetShortLinkByIDWithCache(ctx context.Context, shortLinkID string) (*models.ShortLink, error)
- func (s *Slink) GetShortLinksByURL(ctx context.Context, linkURL string) ([]*models.ShortLink, error)
Constants ¶
const DefaultMaxCreateAttempts = 3
Variables ¶
This section is empty.
Functions ¶
func WithIDGenerator ¶
func WithMaxCreateAttempts ¶
func WithStorage ¶
Types ¶
type CreateInput ¶
type ErrCreateAttemptsExhausted ¶
type ErrCreateAttemptsExhausted struct {
// contains filtered or unexported fields
}
func (*ErrCreateAttemptsExhausted) Error ¶
func (e *ErrCreateAttemptsExhausted) Error() string
type ErrInvalidLinkURL ¶
type ErrInvalidLinkURL struct {
// contains filtered or unexported fields
}
func (*ErrInvalidLinkURL) Error ¶
func (e *ErrInvalidLinkURL) Error() string
type ErrInvalidShortLinkID ¶
type ErrInvalidShortLinkID struct {
// contains filtered or unexported fields
}
func (*ErrInvalidShortLinkID) Error ¶
func (e *ErrInvalidShortLinkID) Error() string
type Slink ¶
type Slink struct {
// contains filtered or unexported fields
}
func (*Slink) CreateShortLink ¶
CreateShortLink unconditionally creates a new ShortLink, even when one with the exact same LinkURL already exists
func (*Slink) GetOrCreateShortLink ¶
func (s *Slink) GetOrCreateShortLink(ctx context.Context, input *CreateInput) (*models.ShortLink, error)
GetOrCreateShortLink returns an existing ShortLink if both LinkURL and ExpiresAt match the input, or creates a new ShortLink if no matching ShortLink can be found.
No normalisation is done on LinkURL. `https://example.com?a=1&b=2` is considered different to `https://example.com?b=2&a1`. Only strict exact string match is used for lookups (whatever's supported by the storage backend).
func (*Slink) GetShortLinkByID ¶
func (s *Slink) GetShortLinkByID(ctx context.Context, shortLinkID string) (*models.ShortLink, error)
GetShortLinkByID looks up a ShortLink by its ID, returing it if found, or nil otherwise.
func (*Slink) GetShortLinkByIDWithCache ¶
func (s *Slink) GetShortLinkByIDWithCache(ctx context.Context, shortLinkID string) (*models.ShortLink, error)
GetShortLinkByIDWithCache looks up ShortLink by the given ID from the LRU cache first, if found it returns it, otherwise it looks the ShortLink up in the storage, and returns it if it's found in the storage, adding it to the LRU cache if found, or it returns nil otherwise.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
slink-admin-server
Package main is `slink-admin-server`.
|
Package main is `slink-admin-server`. |
slink-public-server
Package main is `slink-public-server`.
|
Package main is `slink-public-server`. |
Package debug contains prometheus metric definitions, wrapper functions for tracking metrics, and some code to serve the prometheus metrics and pprof via http.
|
Package debug contains prometheus metric definitions, wrapper functions for tracking metrics, and some code to serve the prometheus metrics and pprof via http. |
Package ids covers mainly ID generation
|
Package ids covers mainly ID generation |
Package models contains the data models used in Slink
|
Package models contains the data models used in Slink |
Package storage provides low-level access to storage
|
Package storage provides low-level access to storage |
Package tracker provides a mechanism to track short link lookups/redirects.
|
Package tracker provides a mechanism to track short link lookups/redirects. |