service

package
v0.0.0-...-3f3c5e4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package service is a generated GoMock package.

Package service is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error represents an error returned by the repository.

const (
	// ErrSlugAlreadyInUse is returned when trying to add a shortened url with a slug already in use.
	ErrSlugAlreadyInUse Error = `slug in use`
	// ErrSlugNotFound is returned when trying to get or delete a slug that could not be found in the service.
	ErrSlugNotFound Error = `slug not found`
	// ErrURLNotFound is returned when trying to get or delete a url that could not be found in the service.
	ErrURLNotFound Error = `url not found`
	// ErrInvalidSlug is returned when trying to use a not valid slug.
	ErrInvalidSlug Error = `slug not valid`
)

func (Error) Error

func (e Error) Error() string

Error returns the string representation of the error.

type FixedLenSlugger

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

FixedLenSlugger is a slugger implementation that returns slugs having fixed length.

func NewFixedLenSlugger

func NewFixedLenSlugger(l int) FixedLenSlugger

NewFixedLenSlugger returns a new FixedLenSlugger.

func (FixedLenSlugger) Slug

func (s FixedLenSlugger) Slug() string

Slug returns a slug having fixed length.

func (FixedLenSlugger) Validate

func (s FixedLenSlugger) Validate(slug string) bool

type MockService

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

MockService is a mock of Service interface

func NewMockService

func NewMockService(ctrl *gomock.Controller) *MockService

NewMockService creates a new mock instance

func (*MockService) Add

Add mocks base method

func (*MockService) Delete

func (m *MockService) Delete(ctx context.Context, slug string) error

Delete mocks base method

func (*MockService) EXPECT

func (m *MockService) EXPECT() *MockServiceMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockService) Get

func (m *MockService) Get(ctx context.Context, slug string) (models.URLShortened, error)

Get mocks base method

func (*MockService) Shorten

func (m *MockService) Shorten(ctx context.Context, url string) (models.URLShortened, error)

Shorten mocks base method

type MockServiceMockRecorder

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

MockServiceMockRecorder is the mock recorder for MockService

func (*MockServiceMockRecorder) Add

func (mr *MockServiceMockRecorder) Add(ctx, shortURL interface{}) *gomock.Call

Add indicates an expected call of Add

func (*MockServiceMockRecorder) Delete

func (mr *MockServiceMockRecorder) Delete(ctx, slug interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockServiceMockRecorder) Get

func (mr *MockServiceMockRecorder) Get(ctx, slug interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockServiceMockRecorder) Shorten

func (mr *MockServiceMockRecorder) Shorten(ctx, url interface{}) *gomock.Call

Shorten indicates an expected call of Shorten

type MockSlugger

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

MockSlugger is a mock of Slugger interface

func NewMockSlugger

func NewMockSlugger(ctrl *gomock.Controller) *MockSlugger

NewMockSlugger creates a new mock instance

func (*MockSlugger) EXPECT

func (m *MockSlugger) EXPECT() *MockSluggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockSlugger) Slug

func (m *MockSlugger) Slug() string

Slug mocks base method

func (*MockSlugger) Validate

func (m *MockSlugger) Validate(arg0 string) bool

Validate mocks base method

type MockSluggerMockRecorder

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

MockSluggerMockRecorder is the mock recorder for MockSlugger

func (*MockSluggerMockRecorder) Slug

func (mr *MockSluggerMockRecorder) Slug() *gomock.Call

Slug indicates an expected call of Slug

func (*MockSluggerMockRecorder) Validate

func (mr *MockSluggerMockRecorder) Validate(arg0 interface{}) *gomock.Call

Validate indicates an expected call of Validate

type Service

type Service interface {
	Add(ctx context.Context, shortURL models.URLShortened) (models.URLShortened, error)
	Get(ctx context.Context, slug string) (models.URLShortened, error)
	Shorten(ctx context.Context, url string) (models.URLShortened, error)
	Delete(ctx context.Context, slug string) error
}

Service defines the behaviour of a service capable of shortening urls, retrieving and deleting shortened ones.

type Slugger

type Slugger interface {
	Slug() string
	Validate(string) bool
}

Slugger defines the behaviour of a component capable of returning a slug.

type URLService

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

URLService implements the Service interface.

func NewURLService

func NewURLService(store repository.Storer, slugger Slugger) URLService

NewURLService returns a new instance of the URLService type.

func (URLService) Add

func (URLService) Delete

func (usvc URLService) Delete(ctx context.Context, slug string) error

Delete deletes the entry related to the input slug from the repository.

func (URLService) Get

func (usvc URLService) Get(ctx context.Context, slug string) (models.URLShortened, error)

func (URLService) Shorten

func (usvc URLService) Shorten(ctx context.Context, url string) (models.URLShortened, error)

Shorten returns the shortened URL and shortens it if not found. Returns an error if any.

Jump to

Keyboard shortcuts

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