shorty: github.com/Clever/shorty/db Index | Files

package db

import "github.com/Clever/shorty/db"

Index

Package Files

db.go postgres_db.go redis.go

Variables

var (
    // ErrNotFound represents the case when a long URL is no found
    ErrNotFound = errors.New("No items found by the db layer")
)

type PostgresDB Uses

type PostgresDB struct {
    SchemaName string
    TableName  string
    // contains filtered or unexported fields
}

PostgresDB represents a connection to a Postgres database.

func (*PostgresDB) DeleteURL Uses

func (pgDB *PostgresDB) DeleteURL(slug string) error

DeleteURL removes a URL from the database.

func (*PostgresDB) GetList Uses

func (pgDB *PostgresDB) GetList() ([]ShortenObject, error)

GetList lists all shortened URLs.

func (*PostgresDB) GetLongURL Uses

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 Uses

func (pgDB *PostgresDB) ShortenURL(slug, longURL, owner string, expires time.Time) error

ShortenURL creates a new record for a shortened URL.

type Redis Uses

type Redis struct {
    // contains filtered or unexported fields
}

Redis is a wrapper over a Redis pool connection.

func (Redis) DeleteURL Uses

func (r Redis) DeleteURL(slug string) error

DeleteURL removes all reference to a URL.

func (Redis) GetList Uses

func (r Redis) GetList() ([]ShortenObject, error)

GetList lists all shortened URLs.

func (Redis) GetLongURL Uses

func (r Redis) GetLongURL(slug string) (string, error)

GetLongURL searches for the short URL reference in order to return the long url.

func (Redis) ShortenURL Uses

func (r Redis) ShortenURL(slug, longURL, owner string, expires time.Time) error

ShortenURL adds a URL object to the db.

type ShortenBackend Uses

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 Uses

func NewPostgresDB() ShortenBackend

NewPostgresDB configures and connects to a postgres database.

func NewRedisDB Uses

func NewRedisDB() ShortenBackend

NewRedisDB connects to Redis and pools connections.

type ShortenObject Uses

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

Package db imports 8 packages (graph) and is imported by 2 packages. Updated 2016-07-30. Refresh now. Tools for package owners.