Documentation ¶
Index ¶
- Constants
- Variables
- func IsEmptyKey(err error) bool
- func IsInvalidValue(err error) bool
- func IsKeyNotFound(err error) bool
- func IsNilError(err error) bool
- func IsRangeNotSatisfiable(err error) bool
- func Register(name string, builder StorageBuilder)
- type Manager
- type Raw
- type StorageBuilder
- type StorageDriver
- type StorageError
- type StorageInfo
- type Store
- func (s *Store) Get(ctx context.Context, raw *Raw) (io.Reader, error)
- func (s *Store) GetBytes(ctx context.Context, raw *Raw) ([]byte, error)
- func (s *Store) Name() string
- func (s *Store) Put(ctx context.Context, raw *Raw, data io.Reader) error
- func (s *Store) PutBytes(ctx context.Context, raw *Raw, data []byte) error
- func (s *Store) Remove(ctx context.Context, raw *Raw) error
- func (s *Store) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error)
- func (s *Store) Type() config.PluginType
Constants ¶
const LocalStorageDriver = "local"
LocalStorageDriver is a const of local storage driver.
Variables ¶
var ( // ErrKeyNotFound is an error which will be returned // when the key can not be found. ErrKeyNotFound = StorageError{codeKeyNotFound, "the key not found"} // ErrEmptyKey is an error when the key is empty. ErrEmptyKey = StorageError{codeEmptyKey, "the key is empty"} // ErrInvalidValue represents the value is invalid. ErrInvalidValue = StorageError{codeInvalidValue, "invalid value"} // ErrRangeNotSatisfiable represents the length of file is insufficient. ErrRangeNotSatisfiable = StorageError{codeRangeNotSatisfiable, "range not satisfiable"} )
Functions ¶
func IsEmptyKey ¶
IsEmptyKey check the error is the key is empty or nil.
func IsInvalidValue ¶
IsInvalidValue check the error is the value is invalid or not.
func IsKeyNotFound ¶
IsKeyNotFound check the error is the key cannot be found.
func IsRangeNotSatisfiable ¶
IsRangeNotSatisfiable check the error is a range not exist error or not.
func Register ¶
func Register(name string, builder StorageBuilder)
Register defines an interface to register a driver with specified name. All drivers should call this function to register itself to the driverFactory.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manage stores.
func NewManager ¶
NewManager create a store manager.
type StorageBuilder ¶
type StorageBuilder func(conf string) (StorageDriver, error)
StorageBuilder is a function that creates a new storage plugin instant with the giving conf.
type StorageDriver ¶
type StorageDriver interface { // Get data from the storage based on raw information. // If the length<=0, the driver should return all data from the raw.offest. // Otherwise, just return the data which starts from raw.offset and the length is raw.length. Get(ctx context.Context, raw *Raw) (io.Reader, error) // Get data from the storage based on raw information. // The data should be returned in bytes. // If the length<=0, the storage driver should return all data from the raw.offest. // Otherwise, just return the data which starts from raw.offset and the length is raw.length. GetBytes(ctx context.Context, raw *Raw) ([]byte, error) // Put the data into the storage with raw information. // The storage will get data from io.Reader as io stream. // If the offset>0, the storage driver should starting at byte raw.offset off. Put(ctx context.Context, raw *Raw, data io.Reader) error // PutBytes puts the data into the storage with raw information. // The data is passed in bytes. // If the offset>0, the storage driver should starting at byte raw.offset off. PutBytes(ctx context.Context, raw *Raw, data []byte) error // Remove the data from the storage based on raw information. Remove(ctx context.Context, raw *Raw) error // Stat determine whether the data exists based on raw information. // If that, and return some info that in the form of struct StorageInfo. // If not, return the ErrNotFound. Stat(ctx context.Context, raw *Raw) (*StorageInfo, error) }
StorageDriver defines an interface to manage the data stored in the driver.
NOTE: It is recommended that the lock granularity of the driver should be in piece. That means that the storage driver could read and write the different pieces of the same file concurrently.
func NewLocalStorage ¶
func NewLocalStorage(conf string) (StorageDriver, error)
NewLocalStorage performs initialization for localStorage and return a StorageDriver.
type StorageError ¶
StorageError represents a storage error.
func (StorageError) Error ¶
func (s StorageError) Error() string
type StorageInfo ¶
StorageInfo includes partial meta information of the data.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a wrapper of the storage which implements the interface of StorageDriver.
func NewStore ¶
func NewStore(name string, builder StorageBuilder, cfg string) (*Store, error)
NewStore create a new Store instance.
func (*Store) Stat ¶
Stat determine whether the data exists based on raw information. If that, and return some info that in the form of struct StorageInfo. If not, return the ErrNotFound.
func (*Store) Type ¶
func (s *Store) Type() config.PluginType
Type return the plugin type: StoragePlugin.