Documentation ¶
Index ¶
- Variables
- type BboltTerse
- func (b *BboltTerse) Close(_ context.Context) (err error)
- func (b *BboltTerse) Delete(ctx context.Context, del models.Delete) (err error)
- func (b *BboltTerse) DeleteOne(ctx context.Context, del models.Delete, shortened string) (err error)
- func (b *BboltTerse) Export(ctx context.Context) (export map[string]models.Export, err error)
- func (b *BboltTerse) ExportOne(ctx context.Context, shortened string) (export models.Export, err error)
- func (b *BboltTerse) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
- func (b *BboltTerse) Insert(_ context.Context, terse *models.Terse) (err error)
- func (b *BboltTerse) Read(_ context.Context, shortened string, visit *models.Visit) (terse *models.Terse, err error)
- func (b *BboltTerse) Update(_ context.Context, terse *models.Terse) (err error)
- func (b *BboltTerse) Upsert(_ context.Context, terse *models.Terse) (err error)
- func (b *BboltTerse) VisitsStore() VisitsStore
- type BboltVisits
- func (b *BboltVisits) Add(_ context.Context, shortened string, visit *models.Visit) (err error)
- func (b *BboltVisits) Close(_ context.Context) (err error)
- func (b *BboltVisits) Delete(_ context.Context, del models.Delete) (err error)
- func (b *BboltVisits) DeleteOne(_ context.Context, del models.Delete, shortened string) (err error)
- func (b *BboltVisits) Export(_ context.Context) (allVisits map[string][]*models.Visit, err error)
- func (b *BboltVisits) ExportOne(_ context.Context, shortened string) (visits []*models.Visit, err error)
- func (b *BboltVisits) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
- type MemTerse
- func (m *MemTerse) Close(_ context.Context) (err error)
- func (m *MemTerse) Delete(ctx context.Context, del models.Delete) (err error)
- func (m *MemTerse) DeleteOne(ctx context.Context, del models.Delete, shortened string) (err error)
- func (m *MemTerse) Export(ctx context.Context) (export map[string]models.Export, err error)
- func (m *MemTerse) ExportOne(ctx context.Context, shortened string) (export models.Export, err error)
- func (m *MemTerse) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
- func (m *MemTerse) Insert(_ context.Context, terse *models.Terse) (err error)
- func (m *MemTerse) Read(_ context.Context, shortened string, visit *models.Visit) (terse *models.Terse, err error)
- func (m *MemTerse) Update(_ context.Context, terse *models.Terse) (err error)
- func (m *MemTerse) Upsert(_ context.Context, terse *models.Terse) (err error)
- func (m *MemTerse) VisitsStore() VisitsStore
- type MemVisits
- func (m *MemVisits) Add(_ context.Context, shortened string, visit *models.Visit) (err error)
- func (m *MemVisits) Close(_ context.Context) (err error)
- func (m *MemVisits) Delete(_ context.Context, del models.Delete) (err error)
- func (m *MemVisits) DeleteOne(_ context.Context, del models.Delete, shortened string) (err error)
- func (m *MemVisits) Export(_ context.Context) (allVisits map[string][]*models.Visit, err error)
- func (m *MemVisits) ExportOne(_ context.Context, shortened string) (visits []*models.Visit, err error)
- func (m *MemVisits) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
- type TerseStore
- func NewBboltTerse(db *bbolt.DB, createCtx ctxCreator, group *ctxerrgroup.Group, ...) (terseStore TerseStore)
- func NewMemTerse(createCtx ctxCreator, errChan chan<- error, group *ctxerrgroup.Group, ...) (terseStore TerseStore)
- func NewTerseStore(configJSON json.RawMessage, createCtx ctxCreator, errChan chan<- error, ...) (terseStore TerseStore, storeType string, err error)
- type VisitsStore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrShortenedNotFound indicates the given shortened URL was not found in the underlying storage. ErrShortenedNotFound = errors.New("the shortened URL was not found") // ErrShortenedExists indicates that an attempt was made to add a shortened URL that already existed. ErrShortenedExists = errors.New("the shortened URL already exists") )
Functions ¶
This section is empty.
Types ¶
type BboltTerse ¶
type BboltTerse struct {
// contains filtered or unexported fields
}
BboltTerse is a TerseStore implementation that relies on a bbolt file for the backend storage.
func (*BboltTerse) Close ¶
func (b *BboltTerse) Close(_ context.Context) (err error)
Close closes the connection to the underlying storage. The ctxerrgroup will be killed. This will not close the connection to the VisitsStore. This implementation has no network activity and ignores the given context.
func (*BboltTerse) Delete ¶
Delete deletes data according to the del argument. If the VisitsStore is not nil, then the same method will be called for the associated VisitsStore. This implementation has no network activity and ignores the given context.
func (*BboltTerse) DeleteOne ¶
func (b *BboltTerse) DeleteOne(ctx context.Context, del models.Delete, shortened string) (err error)
DeleteOne deletes data according to the del argument for the given shortened URL. No error should be given if the shortened URL is not found. If the VisitsStore is not nil, then the same method will be called for the associated VisitsStore. This implementation has no network activity and ignores the given context.
func (*BboltTerse) Export ¶
Export returns a map of shortened URLs to export data. This implementation has no network activity and ignores the given context.
func (*BboltTerse) ExportOne ¶
func (b *BboltTerse) ExportOne(ctx context.Context, shortened string) (export models.Export, err error)
ExportOne returns a export of Terse and Visit data for a given shortened URL. The error must be storage.ErrShortenedNotFound if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*BboltTerse) Import ¶
func (b *BboltTerse) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
Import imports the given export's data. If del is not nil, data will be deleted accordingly. If del is nil, data may be overwritten, but unaffected data will be untouched. If the VisitsStore is not nil, then the same method will be called for the associated VisitsStore. This implementation has no network activity and ignores the given context.
func (*BboltTerse) Insert ¶
Insert adds a Terse to the TerseStore. The shortened URL will be active after this. The error will be storage.ErrShortenedExists if the shortened URL is already present. This implementation has no network activity and ignores the given context.
func (*BboltTerse) Read ¶
func (b *BboltTerse) Read(_ context.Context, shortened string, visit *models.Visit) (terse *models.Terse, err error)
Read retrieves all non-Visit Terse data give its shortened URL. A nil visit may be passed in and the visit should not be recorded. The error must be storage.ErrShortenedNotFound if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*BboltTerse) Update ¶
Update assumes the Terse already exists. It will override all of its values. The error must be storage.ErrShortenedNotFound if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*BboltTerse) Upsert ¶
Upsert will upsert the Terse into the backend storage. This implementation has no network activity and ignores the given context.
func (*BboltTerse) VisitsStore ¶
func (b *BboltTerse) VisitsStore() VisitsStore
VisitsStore returns the VisitsStore.
type BboltVisits ¶
type BboltVisits struct {
// contains filtered or unexported fields
}
BboltVisits if a VisitsStore implementation that relies on a bbolt file for the backend storage.
func (*BboltVisits) Add ¶
Add adds the visit to the visits store. This implementation has no network activity and ignores the given context.
func (*BboltVisits) Close ¶
func (b *BboltVisits) Close(_ context.Context) (err error)
Close lets the garbage collector take care of the old Visits data. This implementation has no network activity and ignores the given context.
func (*BboltVisits) Delete ¶
Delete deletes data according to the del argument. This implementation has no network activity and ignores the given context.
func (*BboltVisits) DeleteOne ¶
DeleteOne deletes data according to the del argument for the shortened URL. No error will be given if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*BboltVisits) Export ¶
Export exports all exports all visits data. This implementation has no network activity and ignores the given context.
func (*BboltVisits) ExportOne ¶
func (b *BboltVisits) ExportOne(_ context.Context, shortened string) (visits []*models.Visit, err error)
ExportOne gets all visits to the shortened URL. The error storage.ErrShortenedNotFound will be given if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*BboltVisits) Import ¶
func (b *BboltVisits) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
Import imports the given export's data. If del is not nil, data will be deleted accordingly. If del is nil, data may be overwritten, but unaffected data will be untouched. This implementation has no network activity and ignores the given context.
type MemTerse ¶
type MemTerse struct {
// contains filtered or unexported fields
}
MemTerse is a TerseStore implementation that stores all data in a Go map in memory.
func (*MemTerse) Close ¶
Close closes the connection to the underlying storage. The ctxerrgroup will be killed. This will not close the connection to the VisitsStore. This implementation has no network activity and ignores the given context.
func (*MemTerse) Delete ¶
Delete deletes data according to the del argument. If the VisitsStore is not nil, then the same method will be called for the associated VisitsStore. This implementation has no network activity and ignores the given context.
func (*MemTerse) DeleteOne ¶
DeleteOne deletes data according to the del argument for the given shortened URL. No error should be given if the shortened URL is not found. If the VisitsStore is not nil, then the same method will be called for the associated VisitsStore. This implementation has no network activity and ignores the given context.
func (*MemTerse) Export ¶
Export returns a map of shortened URLs to export data. This implementation has no network activity and ignores the given context.
func (*MemTerse) ExportOne ¶
func (m *MemTerse) ExportOne(ctx context.Context, shortened string) (export models.Export, err error)
ExportOne returns a export of Terse and Visit data for a given shortened URL. The error must be storage.ErrShortenedNotFound if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*MemTerse) Import ¶
func (m *MemTerse) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
Import imports the given export's data. If del is not nil, data will be deleted accordingly. If del is nil, data may be overwritten, but unaffected data will be untouched. If the VisitsStore is not nil, then the same method will be called for the associated VisitsStore. This implementation has no network activity and ignores the given context.
func (*MemTerse) Insert ¶
Insert adds a Terse to the TerseStore. The shortened URL will be active after this. The error will be storage.ErrShortenedExists if the shortened URL is already present. This implementation has no network activity and ignores the given context.
func (*MemTerse) Read ¶
func (m *MemTerse) Read(_ context.Context, shortened string, visit *models.Visit) (terse *models.Terse, err error)
Read retrieves all non-Visit Terse data give its shortened URL. A nil visit may be passed in and the visit should not be recorded. The error must be storage.ErrShortenedNotFound if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*MemTerse) Update ¶
Update assumes the Terse already exists. It will override all of its values. The error must be storage.ErrShortenedNotFound if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*MemTerse) Upsert ¶
Upsert will upsert the Terse into the backend storage. This implementation has no network activity and ignores the given context.
func (*MemTerse) VisitsStore ¶
func (m *MemTerse) VisitsStore() VisitsStore
VisitsStore returns the VisitsStore.
type MemVisits ¶
type MemVisits struct {
// contains filtered or unexported fields
}
MemVisits is a VisitsStore implementation that stores all data in a Go map in memory.
func (*MemVisits) Add ¶
Add adds the visit to the visits store. This implementation has no network activity and ignores the given context.
func (*MemVisits) Close ¶
Close lets the garbage collector take care of the old Visits data. This implementation has no network activity and ignores the given context.
func (*MemVisits) Delete ¶
Delete deletes data according to the del argument. This implementation has no network activity and ignores the given context.
func (*MemVisits) DeleteOne ¶
DeleteOne deletes data according to the del argument for the shortened URL. No error will be given if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*MemVisits) Export ¶
Export exports all exports all visits data. This implementation has no network activity and ignores the given context.
func (*MemVisits) ExportOne ¶
func (m *MemVisits) ExportOne(_ context.Context, shortened string) (visits []*models.Visit, err error)
ExportOne gets all visits to the shortened URL. The error storage.ErrShortenedNotFound will be given if the shortened URL is not found. This implementation has no network activity and ignores the given context.
func (*MemVisits) Import ¶
func (m *MemVisits) Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error)
Import imports the given export's data. If del is not nil, data will be deleted accordingly. If del is nil, data may be overwritten, but unaffected data will be untouched. This implementation has no network activity and ignores the given context.
type TerseStore ¶
type TerseStore interface { // Close closes the connection to the underlying storage. The ctxerrgroup should be killed. This may or may not // close the connection to the VisitsStore, depending on the configuration. Close(ctx context.Context) (err error) // Delete deletes data according to the del argument. If the VisitsStore is not nil, then the same method will be // called for the associated VisitsStore. Delete(ctx context.Context, del models.Delete) (err error) // DeleteOne deletes data according to the del argument for the given shortened URL. No error should be given if // the shortened URL is not found. If the VisitsStore is not nil, then the same method will be called for the // associated VisitsStore. DeleteOne(ctx context.Context, del models.Delete, shortened string) (err error) // Export returns a map of shortened URLs to export data. Export(ctx context.Context) (export map[string]models.Export, err error) // ExportOne returns a export of Terse and Visit data for a given shortened URL. The error must be // storage.ErrShortenedNotFound if the shortened URL is not found. ExportOne(ctx context.Context, shortened string) (export models.Export, err error) // Import imports the given export's data. If del is not nil, data will be deleted accordingly. If del is nil, data // may be overwritten, but unaffected data will be untouched. If the VisitsStore is not nil, then the same method // will be called for the associated VisitsStore. Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error) // Insert adds a Terse to the TerseStore. The shortened URL will be active after this. The error must be // storage.ErrShortenedExists if the shortened URL is already present. Insert(ctx context.Context, terse *models.Terse) (err error) // Read retrieves all non-Visit Terse data give its shortened URL. A nil visit may be passed in and the visit should // not be recorded. The error must be storage.ErrShortenedNotFound if the shortened URL is not found. Read(ctx context.Context, shortened string, visit *models.Visit) (terse *models.Terse, err error) // Update assumes the Terse already exists. It will override all of its values. The error must be // storage.ErrShortenedNotFound if the shortened URL is not found. Update(ctx context.Context, terse *models.Terse) (err error) // Upsert will upsert the Terse into the backend storage. Upsert(ctx context.Context, terse *models.Terse) (err error) // VisitsStore returns the underlying VisitsStore, which hold the backend storage for tracking visits to shortened // URLs. VisitsStore() VisitsStore }
TerseStore is the Terse storage interface. It allows for Terse storage operations without needing to know how the Terse data is stored.
func NewBboltTerse ¶
func NewBboltTerse(db *bbolt.DB, createCtx ctxCreator, group *ctxerrgroup.Group, terseBucket []byte, visitsStore VisitsStore) (terseStore TerseStore)
NewBboltTerse creates a new BboltTerse given the required assets.
func NewMemTerse ¶
func NewMemTerse(createCtx ctxCreator, errChan chan<- error, group *ctxerrgroup.Group, visitsStore VisitsStore) (terseStore TerseStore)
NewMemTerse creates a new MemTerse given the required assets.
func NewTerseStore ¶
func NewTerseStore(configJSON json.RawMessage, createCtx ctxCreator, errChan chan<- error, group *ctxerrgroup.Group, visitsStore VisitsStore) (terseStore TerseStore, storeType string, err error)
NewTerseStore creates a new TerseStore from the given configJSON. The storeType return value is used for logging.
type VisitsStore ¶
type VisitsStore interface { // Add adds the visit to the visits store. Add(ctx context.Context, shortened string, visit *models.Visit) (err error) // Close closes the connection to the underlying storage. Close(ctx context.Context) (err error) // Delete deletes data according to the del argument. Delete(ctx context.Context, del models.Delete) (err error) // DeleteOne deletes data according to the del argument for the shortened URL. No error should be given if the // shortened URL is not found. DeleteOne(ctx context.Context, del models.Delete, shortened string) (err error) // Export exports all exports all visits data. Export(ctx context.Context) (allVisits map[string][]*models.Visit, err error) // ExportOne gets all visits to the shortened URL. The error must be storage.ErrShortenedNotFound if the shortened // URL is not found. ExportOne(ctx context.Context, shortened string) (visits []*models.Visit, err error) // Import imports the given export's data. If del is not nil, data will be deleted accordingly. If del is nil, data // may be overwritten, but unaffected data will be untouched. Import(ctx context.Context, del *models.Delete, export map[string]models.Export) (err error) }
VisitsStore is the Visits storage interface. It allows for Visits storage operations without needing to know how the Visits data is stored.
func NewBboltVisits ¶
func NewBboltVisits(db *bbolt.DB, visitsBucket []byte) (visitsStore VisitsStore)
NewBboltVisits creates a new NewBboltVisits given the required assets.
func NewMemVisits ¶
func NewMemVisits() (visitsStore VisitsStore)
NewMemVisits creates a new MemVisits.
func NewVisitsStore ¶
func NewVisitsStore(configJSON json.RawMessage) (visitsStore VisitsStore, storeType string, err error)
NewVisitsStore creates a new VisitsStore from the given configJSON. The storeType return value is used for logging.