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
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
Click to show internal directories.
Click to hide internal directories.