data

package
v0.0.0-...-d159530 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenToken

func GenToken() (token string, err error)

GenToken returns a new token, a random string of size tokenBytes

Types

type DB

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

DB contains a pointer to a pool and methods for the database

func (*DB) Connect

func (db *DB) Connect()

Connect opens the pool connection

func (*DB) CreatePair

func (db *DB) CreatePair(target string) (p Pair, err error)

CreatePair creates a new pair in the DB, or replaces an existing one in the extremely unlikely event of a token conflict

func (*DB) Disconnect

func (db *DB) Disconnect()

Disconnect closes the pool connection

func (*DB) GetTarget

func (db *DB) GetTarget(token string) (target string, err error)

GetTarget returns a target URL, given a pair's token It also updates the information on how the tracker is being used

func (*DB) Setup

func (db *DB) Setup() (err error)

Setup executes a query to create tables

type Pair

type Pair struct {
	Token     string
	Target    string
	TimesUsed int
	LastUsed  time.Time
	CreatedAt time.Time
}

Pair is the model for pairs of long and short URLs in the DB

Jump to

Keyboard shortcuts

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