Documentation ¶
Overview ¶
Package db contains the storage layer for the application.
Index ¶
- Variables
- type Click
- type ClickReport
- type ETag
- type GlobalStats
- type Link
- type PublishOpt
- type Store
- func (s *Store) Click(ctx context.Context, c *Click) error
- func (s *Store) ClickCount(ctx context.Context, short string) (int, error)
- func (s *Store) ClickReport(ctx context.Context, short string) (<-chan *ClickReport, error)
- func (s *Store) ClickReportListed(ctx context.Context) (<-chan *ClickReport, error)
- func (s *Store) Delete(ctx context.Context, short, author string) error
- func (s *Store) ETag(ctx context.Context) (ETag, error)
- func (s *Store) Get(ctx context.Context, short string) (*Link, error)
- func (s *Store) List(ctx context.Context, author string) (<-chan *Link, error)
- func (s *Store) ListAll(ctx context.Context) (<-chan *Link, error)
- func (s *Store) Listed(ctx context.Context, limit int) (<-chan *Link, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Publish(ctx context.Context, l *Link, opts ...PublishOpt) (_ *Link, err error)
- func (s *Store) Served(ctx context.Context) (*GlobalStats, error)
- func (s *Store) WithTransaction(parent context.Context) (context.Context, *Tx, error)
- type Tx
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrShortConflict means that a conflicting short-name was chosen. ErrShortConflict = errors.New("the requested short link name already exists") )
Functions ¶
This section is empty.
Types ¶
type ClickReport ¶
A ClickReport can be downloaded.
type ETag ¶
type ETag string
ETag is an opaque value used to track changes in the links table.
const EmptyETag ETag = "<<empty>>"
EmptyETag will be returned when there is no link data.
type GlobalStats ¶
GlobalStats summarizes the total usage.
type Link ¶
type Link struct { Author string // Only the owner can update CreatedAt time.Time // Creation time Comment string // A user-defined comment Count int // Number of times clicked Listed bool // Appears on the front page Public bool // Accessible from outside Short string // The unique short-link value UpdatedAt time.Time // Last-updated time URL string // A well-formed URL }
Link is a shortened link.
type PublishOpt ¶
type PublishOpt int
PublishOpt can be passed to Store.Publish to alter the default behaviors.
const ( // AllowNewAuthor instructs Store.Publish to allow a link to be // taken over by an author other than the one that created it. AllowNewAuthor PublishOpt = iota )
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides access to the short-link data.
func (*Store) ClickCount ¶
ClickCount returns the number of times that the link has been clicked.
func (*Store) ClickReport ¶
ClickReport returns the recorded click information for a specific link.
func (*Store) ClickReportListed ¶
func (s *Store) ClickReportListed(ctx context.Context) (<-chan *ClickReport, error)
ClickReportListed returns click information for all listed links.
func (*Store) Publish ¶
Publish stores or updates the link in the database. This function returns the latest value in the database.
func (*Store) Served ¶
func (s *Store) Served(ctx context.Context) (*GlobalStats, error)
Served returns global statistics.
func (*Store) WithTransaction ¶
WithTransaction returns a new context that represents a database transaction. If the given context already contains a transaction, this method will return it. The transaction will be automatically rolled back if the
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a handle to an underlying database transaction.
type ValidationError ¶
type ValidationError string
ValidationError is returned from Link.Validate().
func (ValidationError) Error ¶
func (v ValidationError) Error() string