Documentation ¶
Overview ¶
Package usecase defines the business logic of the requirement. The general flow of the requirements are explicitly stated in the code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckHealth ¶
type CheckHealth interface { // Check checks the health of the system, including its dependencies. Check(ctx context.Context) error }
CheckHealth is the interface that defines the health check.
type CheckHealthRepository ¶
type CheckHealthRepository interface { // IsAlive must returns true if the repository can connect without any problem. IsAlive(ctx context.Context) bool }
CheckHealthRepository is the interface that defines the repository health check.
type CreateShortURL ¶
type CreateShortURL interface { // Create creates a short version of the given URL. Create(ctx context.Context, url string) (*entity.URL, error) }
CreateShortURL is the interface that defines the short URL creation.
type CreateShortURLRepository ¶
type CreateShortURLRepository interface { // Save saves the URL in the repository. Save(ctx context.Context, url *entity.URL) error }
CreateShortURLRepository defines the repository for URL.
type GetURL ¶
type GetURL interface { // GetAll gets all URL available in system. GetAll(ctx context.Context) ([]*entity.URL, error) // GetByCode gets a single data available in system based on code. GetByCode(ctx context.Context, code string) (*entity.URL, error) }
GetURL is the interface that defines the URL retrieve process.
type GetURLRepository ¶
type GetURLRepository interface { // GetAll gets all URL available in repository. GetAll(ctx context.Context) ([]*entity.URL, error) // GetByCode gets a single data available in repository based on code. // If the data is not found, it returns ErrURLNotFound. GetByCode(ctx context.Context, code string) (*entity.URL, error) }
GetURLRepository defines the contract to get URL.
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker is responsible for doing the health check.
func NewHealthChecker ¶
func NewHealthChecker(repo CheckHealthRepository) *HealthChecker
NewHealthChecker creates an instance of HealthChecker.
type ShortURLCreator ¶
type ShortURLCreator struct {
// contains filtered or unexported fields
}
ShortURLCreator is responsible for creating a unique short URL.
func NewShortURLCreator ¶
func NewShortURLCreator(generator URLGenerator, repo CreateShortURLRepository) *ShortURLCreator
NewShortURLCreator creates an instance of ShortURLCreator.
func (*ShortURLCreator) Create ¶
Create creates a short URL for the given URL. It tries to ensure that the short URL is unique from the rest. If it is unsuccessful in creating a unique short URL, it will return error.
Currently, it does not check if the URL is valid. It only checks whether the URL is empty.
type URLGenerator ¶
type URLGenerator interface { // Generate generates a short URL with defined length. // The first return value is code, the second is short URL. Generate(length uint) (string, string, error) }
URLGenerator defines the short URL generator.
type URLGetter ¶
type URLGetter struct {
// contains filtered or unexported fields
}
URLGetter is responsible to get URL.
func NewURLGetter ¶
func NewURLGetter(repo GetURLRepository) *URLGetter
NewURLGetter creates an instance of URLGetter.