Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrNotFound ¶
type ErrNotFound struct{}
func (ErrNotFound) Error ¶
func (e ErrNotFound) Error() string
type PostgresDB ¶
type PostgresDB struct { SchemaName string TableName string // contains filtered or unexported fields }
PostgresDB represents a connection to a Postgres database.
func (*PostgresDB) DeleteURL ¶
func (pgDB *PostgresDB) DeleteURL(slug string) error
DeleteURL removes a URL from the database.
func (*PostgresDB) GetList ¶
func (pgDB *PostgresDB) GetList() ([]ShortenObject, error)
GetList lists all shortened URLs.
func (*PostgresDB) GetLongURL ¶
func (pgDB *PostgresDB) GetLongURL(slug string) (string, error)
GetLongURL searches for the short URL reference in order to return the long url.
func (*PostgresDB) ShortenURL ¶
func (pgDB *PostgresDB) ShortenURL(slug, longURL, owner string, expires time.Time) error
ShortenURL creates a new record for a shortened URL.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis is a wrapper over a Redis pool connection.
func (Redis) GetList ¶
func (r Redis) GetList() ([]ShortenObject, error)
GetList lists all shortened URLs.
func (Redis) GetLongURL ¶
GetLongURL searches for the short URL reference in order to return the long url.
type ShortenBackend ¶
type ShortenBackend interface { DeleteURL(slug string) error ShortenURL(slug, longURL, owner string, expires time.Time) error GetLongURL(slug string) (string, error) GetList() ([]ShortenObject, error) }
ShortenBackend represents the necessary interface for storing and updating URLs.
func NewPostgresDB ¶
func NewPostgresDB() ShortenBackend
NewPostgresDB configures and connects to a postgres database.
func NewRedisDB ¶
func NewRedisDB() ShortenBackend
NewRedsDB connects to Redis and pools connections.
type ShortenObject ¶
type ShortenObject struct { Slug string `json:"slug"` Owner string `json:"owner"` LongURL string `json:"long_url"` Modified time.Time `json:"modified_date,omitempty"` Expires time.Time `json:"expire_date,omitempty"` }
ShortenObject holds the metadata and the mapping for a shortened URL I like the NullTime concept from the pq library, so even for other backends let's use it instead of checking whether the date is 0001-01-01