db

package
v0.0.0-...-cf1b590 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB struct to hold the database connection pool.

func New

func New(user, password, host, dbname string, port int) (*DB, error)

New creates a new DB instance.

func (*DB) Close

func (db *DB) Close()

Close closes the database connection pool.

func (*DB) GetOriginalURL

func (db *DB) GetOriginalURL(shortURL string) (string, error)

GetOriginalURL gets the original URL from the short URL.

func (*DB) StoreURLs

func (db *DB) StoreURLs(shortURL, originalURL string) (string, error)

StoreURLs stores the short URL and original URL in the database.

type Database

type Database interface {
	StoreURLs(shortURL, originalURL string) (string, error)
	GetOriginalURL(shortURL string) (string, error)
	Close()
}

Database interface to hold the database methods.

type URLMap

type URLMap struct {
	CreatedAt   time.Time `db:"created_at"`
	ShortURL    string    `db:"short_url"`
	OriginalURL string    `db:"original_url"`
	Hits        int64     `db:"hits"`
}

URLMap struct to hold the URL map.

Jump to

Keyboard shortcuts

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