db

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

func NewStore

func NewStore(ctx context.Context, uri string) (*Store, error)

NewStore parses the given URI and returns the database instantiation.

func (*Store) Close

func (db *Store) Close() (err error)

func (*Store) DeleteAlias

func (db *Store) DeleteAlias(ctx context.Context, a string) (err error)

DeleteAlias deletes a given short alias if exists.

func (*Store) FetchAlias

func (db *Store) FetchAlias(ctx context.Context, a string) (*models.Redir, error)

FetchAlias reads a given alias and returns the associated link.

func (*Store) FetchAliasAll

func (db *Store) FetchAliasAll(
	ctx context.Context,
	public bool,
	pageSize, pageNum int64,
) ([]models.RedirIndex, int64, error)

FetchAliasAll reads all aliases by given page size and page number.

func (*Store) RecordVisit

func (db *Store) RecordVisit(ctx context.Context, v *models.Visit) (string, error)

RecordVisit records a visit event. If the visit is a new user, it returns and ID to set a cookie to the user.

func (*Store) StatReferer

func (db *Store) StatReferer(
	ctx context.Context,
	a string,
	start, end time.Time,
) ([]models.RefStat, error)

StatReferer fetches and counts all referers of a given alias

func (*Store) StatUA

func (db *Store) StatUA(
	ctx context.Context,
	a string,
	start, end time.Time,
) ([]models.UAStat, error)

func (*Store) StatVisit

func (db *Store) StatVisit(ctx context.Context, as []string) (rs []models.VisitRecord, err error)

StatVisit counts the PV/UV of given aliases.

The current approach is to use visitor's IP address.

func (*Store) StatVisitHist

func (db *Store) StatVisitHist(
	ctx context.Context,
	a string,
	start, end time.Time,
) ([]models.TimeHist, error)

StatVisitHist is a enhanced version of StatVisit. It offers the ability to query PV/UV for a range of time.

The current approach is to count IP address.

func (*Store) StoreAlias

func (db *Store) StoreAlias(ctx context.Context, r *models.Redir) (err error)

StoreAlias stores a given short alias with the given link if not exists

func (*Store) UpdateAlias

func (db *Store) UpdateAlias(ctx context.Context, r *models.Redir) error

UpdateAlias updates the link of a given alias

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL