repository

package
v0.0.0-...-d3d161b Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mock

type Mock struct {
	GetShortURLFunc  func(ctx context.Context, longURL string) (string, error)
	GetLongURLFunc   func(ctx context.Context, shortURL string) (string, error)
	GetStatsFunc     func(ctx context.Context, shortURL string) (int, error)
	SaveShortURLFunc func(ctx context.Context, longURL, shortURL string) error
}

func (*Mock) GetLongURL

func (m *Mock) GetLongURL(ctx context.Context, shortURL string) (string, error)

func (*Mock) GetShortURL

func (m *Mock) GetShortURL(ctx context.Context, longURL string) (string, error)

func (*Mock) GetStats

func (m *Mock) GetStats(ctx context.Context, shortURL string) (int, error)

func (*Mock) SaveShortURL

func (m *Mock) SaveShortURL(ctx context.Context, longURL, shortURL string) error

type PostgreSQL

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

PostgreSQL is a repository that implements the Repository interface.

func NewPostgreSQL

func NewPostgreSQL(logger *zap.Logger, dbConn db) *PostgreSQL

NewPostgreSQL creates a new PostgreSQL repository.

func (*PostgreSQL) GetLongURL

func (p *PostgreSQL) GetLongURL(ctx context.Context, shortURL string) (string, error)

GetLongURL returns the long URL for a given short URL.

func (*PostgreSQL) GetShortURL

func (p *PostgreSQL) GetShortURL(ctx context.Context, longURL string) (string, error)

GetShortURL returns the short URL for a given long URL.

func (*PostgreSQL) GetStats

func (p *PostgreSQL) GetStats(ctx context.Context, shortURL string) (int, error)

Get sats for a given short URL.

func (*PostgreSQL) SaveShortURL

func (p *PostgreSQL) SaveShortURL(ctx context.Context, shortURL, longURL string) error

SaveShortURL saves a short URL to the database.

type Repository

type Repository interface {
	GetShortURL(ctx context.Context, longURL string) (string, error)
	GetLongURL(ctx context.Context, shortURL string) (string, error)
	GetStats(ctx context.Context, shortURL string) (int, error)
	SaveShortURL(ctx context.Context, longURL, shortURL string) error
}

Repository is an interface that defines the methods that a repository should implement.

Jump to

Keyboard shortcuts

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