repository

package
v0.0.0-...-c2aaf4c Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package repository provides real implementation of storing data. It doesn't necessarily a database. It can be a file or in-memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetURLCache

type GetURLCache interface {
	// Get gets a URL from the cache.
	Get(ctx context.Context, code string) (*entity.URL, error)
	InsertURLCache
}

GetURLCache defines the interface to get URL from the cache.

type GetURLDatabase

type GetURLDatabase interface {
	// GetAll gets all URLs from the database.
	GetAll(ctx context.Context) ([]*entity.URL, error)
	// GetByCode gets a single URL from the database.
	// If the URL can't be found, it returns entity.ErrNotFound().
	GetByCode(ctx context.Context, code string) (*entity.URL, error)
}

GetURLDatabase defines the interface to get URL from the database.

type HealthChecker

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

HealthChecker is responsible to check all dependencies' condition.

func NewHealthChecker

func NewHealthChecker(deps ...HealthCheckerRepository) *HealthChecker

NewHealthChecker creates an instance of HealthChecker.

func (*HealthChecker) IsAlive

func (hc *HealthChecker) IsAlive(ctx context.Context) bool

IsAlive must returns true if all dependencies can connect without any problem.

type HealthCheckerRepository

type HealthCheckerRepository interface {
	// IsAlive must returns true if the system can connect without any problem.
	IsAlive(ctx context.Context) bool
}

HealthCheckerRepository is the interface that defines the repository health check.

type InsertURLCache

type InsertURLCache interface {
	// Save saves a new URL into the cache.
	Save(ctx context.Context, url *entity.URL) error
}

InsertURLCache defines the interface to insert a new URL to the cache.

type InsertURLDatabase

type InsertURLDatabase interface {
	// Insert inserts a new URL into the database.
	// It must handle if the data already exists.
	Insert(ctx context.Context, url *entity.URL) error
}

InsertURLDatabase defines the interface to insert a new URL to the database.

type URLGetter

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

URLGetter is responsible to get URL from storage. It uses database and cache.

func NewURLGetter

func NewURLGetter(database GetURLDatabase, cache GetURLCache) *URLGetter

NewURLGetter creates an instance of URLGetter.

func (*URLGetter) GetAll

func (ug *URLGetter) GetAll(ctx context.Context) ([]*entity.URL, error)

GetAll gets all URLs from storage.

func (*URLGetter) GetByCode

func (ug *URLGetter) GetByCode(ctx context.Context, code string) (*entity.URL, error)

GetByCode gets a single URL from storage. If the URL can't be found, it returns entity.ErrNotFound().

type URLInserter

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

URLInserter is responsible to insert a new URL into storage. It uses database and cache.

func NewURLInserter

func NewURLInserter(database InsertURLDatabase, cache InsertURLCache) *URLInserter

NewURLInserter creates an instance of URLInserter.

func (*URLInserter) Save

func (ui *URLInserter) Save(ctx context.Context, url *entity.URL) error

Save saves a new URL into the storage. First, it inserts to database. If success, the data will be inserted to cache. It ignores the error from cache since it can always be generated when retrieving the data. But, it doesn't ignore the error from the database.

Directories

Path Synopsis
Package cache provides real connection to the cache.
Package cache provides real connection to the cache.
Package database provides real connection to the database.
Package database provides real connection to the database.

Jump to

Keyboard shortcuts

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