Documentation ¶
Overview ¶
Package storage provides a simple interface to store and retrieve data from multiple data stores.
Index ¶
- Constants
- Variables
- func ParseToStruct(from, to any) error
- type Func
- type HookFunc
- type IStorage
- type Mock
- func (m *Mock) Count(ctx context.Context, target string, prm *count.Count, ...) (int64, error)
- func (m *Mock) Delete(ctx context.Context, id, target string, prm *delete.Delete, ...) error
- func (m *Mock) Get(ctx context.Context, id, target string, v any, prm *get.Get, ...) error
- func (m *Mock) GetClient() any
- func (m *Mock) GetName() string
- func (m *Mock) List(ctx context.Context, target string, v any, prm *list.List, ...) error
- func (m *Mock) Set(ctx context.Context, id, target string, v any, prm *set.Set, ...) (string, error)
- func (m *Mock) Update(ctx context.Context, id, target string, v any, prm *update.Update, ...) error
- type Options
- type Storage
- func (s *Storage) GetCounterCount() *expvar.Int
- func (s *Storage) GetCounterDelete() *expvar.Int
- func (s *Storage) GetCounterGet() *expvar.Int
- func (s *Storage) GetCounterList() *expvar.Int
- func (s *Storage) GetCounterSet() *expvar.Int
- func (s *Storage) GetCounterUpdate() *expvar.Int
- func (s *Storage) GetLogger() sypl.ISypl
- func (s *Storage) GetName() string
- func (s *Storage) GetType() string
Constants ¶
const ( DefaultMetricCounterLabel = "counter" Type = "storage" // Operation names. OperationCount = "count" OperationCreate = "create" OperationDelete = "delete" OperationList = "list" OperationRetrieve = "retrieve" OperationUpdate = "update" )
Type is the type of the entity regarding the framework. It is used to for example, to identify the entity in the logs, metrics, and for tracing.
Variables ¶
var ( // ErrRequiredPostHook is the error returned when the post-hook function is // missing. ErrRequiredPostHook = customerror.NewRequiredError("post-hook function", customerror.WithCode("ERR_REQUIRED_POST_HOOK")) // ErrRequiredPreHook is the error returned when the pre-hook function is // missing. ErrRequiredPreHook = customerror.NewRequiredError("pre-hook function", customerror.WithCode("ERR_REQUIRED_PRE_HOOK")) )
Functions ¶
func ParseToStruct ¶
ParseToStruct parses the given JSON (`from`) to struct (`to`).
Types ¶
type Func ¶
Func allows to set options.
func WithPostHook ¶
WithPostHook set the post-hook function.
func WithPreHook ¶
WithPreHook set the pre-hook function.
type IStorage ¶
type IStorage interface { // Count counts data. Count(ctx context.Context, target string, prm *count.Count, options ...Func[*count.Count]) (int64, error) // Delete removes data. Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...Func[*delete.Delete]) error // Get retrieves data. Get(ctx context.Context, id, target string, v any, prm *get.Get, options ...Func[*get.Get]) error // List data. List(ctx context.Context, target string, v any, prm *list.List, options ...Func[*list.List]) error // Set stores data. Set(ctx context.Context, id, target string, v any, prm *set.Set, options ...Func[*set.Set]) (string, error) // Update updates data. Update(ctx context.Context, id, target string, v any, prm *update.Update, options ...Func[*update.Update]) error // GetName returns the storage name. GetName() string // GetClient returns the storage client. Use that to interact with the // underlying storage client. GetClient() any }
IStorage defines the data access layer interface.
The Data Access Layer (DAL) is generally more abstract and wider than the Data Access Object (DAO).
The DAL is responsible for providing a consistent and unified interface to access data from different data sources (such as databases, files, or web services) regardless of their underlying implementation details. It abstracts away the complexity of data access by providing a simple, unified interface that shields the rest of the application from the underlying data storage details.
On the other hand, the DAO is typically more specific to a particular data source, such as a particular database management system (such as MySQL or MongoDB) or a particular web service API. Its primary responsibility is to abstract away the details of the underlying data source and provide a simplified interface for performing CRUD (Create, Read, Update, Delete) operations on that data source.
So while both DAL and DAO are used to abstract away the complexities of data access, the DAL is generally wider and more abstract because it deals with multiple data sources, while the DAO is more specific and deals with a particular data source.
type Mock ¶
type Mock struct { MockCount func(ctx context.Context, target string, prm *count.Count, options ...Func[*count.Count]) (int64, error) MockDelete func(ctx context.Context, id, target string, prm *delete.Delete, options ...Func[*delete.Delete]) error MockGet func(ctx context.Context, id, target string, v any, prm *get.Get, options ...Func[*get.Get]) error MockList func(ctx context.Context, target string, v any, prm *list.List, opts ...Func[*list.List]) error MockSet func(ctx context.Context, id, target string, v any, prm *set.Set, options ...Func[*set.Set]) (string, error) MockUpdate func(ctx context.Context, id, target string, v any, prm *update.Update, opts ...Func[*update.Update]) error MockGetClient func() any MockGetName func() string }
Mock is a struct which satisfies the storage.IStorage interface.
func (*Mock) Count ¶
func (m *Mock) Count(ctx context.Context, target string, prm *count.Count, options ...Func[*count.Count]) (int64, error)
Count counts data.
func (*Mock) Delete ¶
func (m *Mock) Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...Func[*delete.Delete]) error
Delete removes data.
func (*Mock) Get ¶
func (m *Mock) Get(ctx context.Context, id, target string, v any, prm *get.Get, options ...Func[*get.Get]) error
Get retrieves data.
func (*Mock) GetClient ¶
GetClient returns the storage client. Use that to interact with the underlying storage client.
func (*Mock) List ¶
func (m *Mock) List(ctx context.Context, target string, v any, prm *list.List, opts ...Func[*list.List]) error
List data.
type Options ¶
type Options[T any] struct { // PreHookFunc is the function which runs before the operation. PreHookFunc HookFunc[T] `json:"-"` // PostHookFunc is the function which runs after the operation. PostHookFunc HookFunc[T] `json:"-"` }
Options for operations.
type Storage ¶
type Storage struct { // Logger. Logger sypl.ISypl `json:"-" validate:"required"` // Name of the storage type. Name string `json:"name" validate:"required,lowercase,gte=1"` // contains filtered or unexported fields }
Storage definition.
func (*Storage) GetCounterCount ¶
GetCounterCount returns the counterCount metric.
func (*Storage) GetCounterDelete ¶
GetCounterDelete returns the counterDelete metric.
func (*Storage) GetCounterGet ¶
GetCounterGet returns the counterGet metric.
func (*Storage) GetCounterList ¶
GetCounterList returns the counterList metric.
func (*Storage) GetCounterSet ¶
GetCounterSet returns the counterSet metric.
func (*Storage) GetCounterUpdate ¶
GetCounterUpdate returns the counterUpdate metric.