Documentation ¶
Overview ¶
Package db contains interface and struct types to be implemented by storage backends.
Index ¶
Constants ¶
View Source
const ( // ErrAlreadyExists is returned when a URL with the given name already exists. ErrAlreadyExists = errors.Sentinel("url with this name already exists") // ErrNotFound is returned when a URL with the given name doesn't exist. ErrNotFound = errors.Sentinel("url with this name doesn't exist") // ErrUserNotFound is returned when the given user is not found. ErrUserNotFound = errors.Sentinel("user not found") )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
type DB interface { // URL returns the full URL of the given short link URL(short string) (u URL, err error) // RandomURL generates a random short URL RandomURL(userID uuid.UUID, url string) (u URL, err error) // NamedURL creates a short URL with the given name NamedURL(userID uuid.UUID, short, url string) (u URL, err error) // User returns the user with the given UUID. User(id uuid.UUID) (u User, err error) // CreateUser creates a user with the given username CreateUser(name string) (u User, token string, err error) // ValidateToken validates the given token ValidateToken(token string) (u *User, valid bool, err error) // RegenerateToken generates a new token RegenerateToken(id uuid.UUID) (token string, err error) }
DB is a database to store URLs, their expiration, and users.
type URL ¶
type URL struct { ID uuid.UUID `json:"id"` // The short URL Short string `json:"short"` // The full URL to redirect to URL string `json:"url"` // The user that created this short URL User User `json:"user"` // The time this URL expires and is removed from the database, nil if it doesn't expire. Expires *time.Time `json:"expires,omitempty"` }
URL is a single short URL.
Click to show internal directories.
Click to hide internal directories.