Documentation ¶
Index ¶
- type IDGenerator
- type InMemoryStore
- func (s *InMemoryStore) DeleteAll(_ context.Context) error
- func (s *InMemoryStore) DeleteOne(_ context.Context, id string) error
- func (s *InMemoryStore) GetAll(_ context.Context) ([]Item, error)
- func (s *InMemoryStore) GetOne(_ context.Context, id string) (Item, error)
- func (s *InMemoryStore) Store(_ context.Context, item Item) error
- type Item
- type ItemUpdate
- type NewItem
- type NotFoundError
- type Service
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IDGenerator ¶
IDGenerator generates a new ID.
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore keeps items in the memory. Use it in tests or for development/demo purposes.
func NewInMemoryStore ¶
func NewInMemoryStore() *InMemoryStore
NewInMemoryStore returns a new in-memory item store.
func (*InMemoryStore) DeleteAll ¶
func (s *InMemoryStore) DeleteAll(_ context.Context) error
DeleteItems deletes all items from the store.
func (*InMemoryStore) DeleteOne ¶
func (s *InMemoryStore) DeleteOne(_ context.Context, id string) error
DeleteOne deletes a single item by its ID.
func (*InMemoryStore) GetAll ¶
func (s *InMemoryStore) GetAll(_ context.Context) ([]Item, error)
GetAll returns all items.
type ItemUpdate ¶
ItemUpdate contains updates of an existing item.
type NotFoundError ¶
type NotFoundError struct {
ID string
}
NotFoundError is returned if an item cannot be found.
func (NotFoundError) Details ¶
func (e NotFoundError) Details() []interface{}
Details returns error details.
func (NotFoundError) Error ¶
func (NotFoundError) Error() string
Error implements the error interface.
func (NotFoundError) NotFound ¶
func (NotFoundError) NotFound() bool
NotFound tells a client that this error is related to a resource being not found. Can be used to translate the error to eg. status code.
func (NotFoundError) ServiceError ¶
func (NotFoundError) ServiceError() bool
ServiceError tells the transport layer whether this error should be translated into the transport format or an internal error should be returned instead.
type Service ¶
type Service interface { // AddItem adds a new item to the list. AddItem(ctx context.Context, newItem NewItem) (item Item, err error) // ListItems returns a list of items. ListItems(ctx context.Context) (items []Item, err error) // DeleteItems deletes all items from the list. DeleteItems(ctx context.Context) error // GetItem returns the details of an item. GetItem(ctx context.Context, id string) (item Item, err error) // UpdateItem updates an existing item. UpdateItem(ctx context.Context, id string, itemUpdate ItemUpdate) (item Item, err error) // DeleteItem deletes an item from the list. DeleteItem(ctx context.Context, id string) error }
Service manages a todo list.
func NewService ¶
func NewService(idgenerator IDGenerator, store Store) Service
NewService returns a new Service.
type Store ¶
type Store interface { // Store stores an item. Store(ctx context.Context, item Item) error // GetAll returns all items. GetAll(ctx context.Context) ([]Item, error) // DeleteItems deletes all items in the store. DeleteAll(ctx context.Context) error // GetOne returns a single item by its ID. GetOne(ctx context.Context, id string) (Item, error) // DeleteOne deletes a single item by its ID. DeleteOne(ctx context.Context, id string) error }
Store persists items.