model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = errors.New("record not found")

ErrRecordNotFound represents an error for not finding an error in DB

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	ErrCounter *prometheus.CounterVec
	Histogram  *prometheus.HistogramVec
}

Metrics keeps global Prometheus metrics.

type RedisURLCounterRepo

type RedisURLCounterRepo struct {
	RedisMasterClient redis.Cmdable
	RedisSlaveClient  redis.Cmdable
}

RedisURLCounterRepo represent repository model for redis.

func (RedisURLCounterRepo) Decr

func (r RedisURLCounterRepo) Decr(id uint64, count int64) (finalErr error)

Decr decreases the counter value each time a shorted URL is called.

func (RedisURLCounterRepo) Get

func (r RedisURLCounterRepo) Get(key string) (_ int64, finalErr error)

Get returns value of a key.

func (RedisURLCounterRepo) Incr

func (r RedisURLCounterRepo) Incr(id uint64) (finalErr error)

Incr increases a counter value each time a shorted URL is called.

func (RedisURLCounterRepo) Keys

func (r RedisURLCounterRepo) Keys() (_ []string, finalErr error)

Keys returns all keys from redis.

type RedisURLRepo added in v1.1.0

type RedisURLRepo struct {
	Base              URLRepo
	RedisMasterClient redis.Cmdable
	RedisSlaveClient  redis.Cmdable
}

RedisURLRepo represent repository model for redis cache.

func (RedisURLRepo) Create added in v1.1.0

func (r RedisURLRepo) Create(url *URL) error

Create creates a new shorted url in database.

func (RedisURLRepo) FindByID added in v1.1.0

func (r RedisURLRepo) FindByID(id uint64) (*URL, error)

FindByID finds a url in cache by ID.

func (RedisURLRepo) Update added in v1.1.0

func (r RedisURLRepo) Update(id uint64, additionalCount int64) error

Update updates count column in database.

type SQLURLRepo

type SQLURLRepo struct {
	MasterDB *gorm.DB
	SlaveDB  *gorm.DB
}

SQLURLRepo represents repository model for SQL databases.

func (SQLURLRepo) Create

func (s SQLURLRepo) Create(url *URL) (finalErr error)

Create creates a new shorted url in database.

func (SQLURLRepo) FindByID

func (s SQLURLRepo) FindByID(id uint64) (_ *URL, finalErr error)

FindByID finds a url in database by ID.

func (SQLURLRepo) Update

func (s SQLURLRepo) Update(id uint64, additionalCount int64) (finalErr error)

Update updates count column in database.

type URL

type URL struct {
	gorm.Model
	URL   string `json:"url"`
	Count int64  `json:"count"`
}

URL represents url table structure.

type URLCounterRepo

type URLCounterRepo interface {
	Incr(id uint64) error
	Decr(id uint64, count int64) error
	Keys() ([]string, error)
	Get(key string) (int64, error)
}

URLCounterRepo represent repository model for counter.

type URLRepo

type URLRepo interface {
	Create(url *URL) error
	FindByID(id uint64) (*URL, error)
	Update(id uint64, additionalCount int64) error
}

URLRepo represents repository model.

Jump to

Keyboard shortcuts

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