link

package
v0.0.0-...-c8dc403 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthentication = errors.New("authentication failed")

ErrAuthentication is returned when the provided credentials cannot be validated.

View Source
var ErrInactive = errors.New("link is inactive")

ErrInactive is returned when trying to redirect to a link that has been inactivated.

View Source
var ErrNotFound = errors.New("link not found")

ErrNotFound is returned when a Link is not found by any of its attributes.

Functions

This section is empty.

Types

type InMemoryRepository

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

func NewInMemoryRepository

func NewInMemoryRepository() *InMemoryRepository

func (*InMemoryRepository) FindByID

func (r *InMemoryRepository) FindByID(ctx context.Context, ID int) (Link, error)

func (*InMemoryRepository) Save

func (r *InMemoryRepository) Save(ctx context.Context, l Link) (int, error)

func (*InMemoryRepository) Update

func (r *InMemoryRepository) Update(ctx context.Context, l Link) error
type Link struct {
	ID       int
	URL      string
	Password []byte
	Count    int
	Inactive bool
}

Link represents an underlying URL with statistics on how it is used.

type Repository

type Repository interface {
	Save(ctx context.Context, l Link) (int, error)
	Update(ctx context.Context, l Link) error
	FindByID(ctx context.Context, ID int) (Link, error)
}

Repository encapsulates the storage of a Link.

type Service

type Service interface {
	Create(ctx context.Context, url, password string) (Link, error)
	Redirect(ctx context.Context, ID int, password string) (Link, error)
	FindByID(ctx context.Context, ID int) (Link, error)
	Inactivate(ctx context.Context, ID int) error
}

Service encapsulates the business logic of a Link. As stated by this principle https://golang.org/doc/effective_go#generality, since the underlying concrete implementation does not export any other method that is not in the interface, we decided to define it where it is implemented rather where it is used (commonly in a handler).

func NewService

func NewService(r Repository) Service

Jump to

Keyboard shortcuts

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