| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package storage
- import (
- "os"
- "time"
- )
- // DoesNotExistError is used as a generic error to return when a target path does not
- // exist in storage. Equivalent to os.ErrorNotExist such that it will work with os.IsNotExist(err)
- var DoesNotExistError = os.ErrNotExist
- // StorageInfo is a data object containing basic information about the path in storage.
- type StorageInfo struct {
- Name string // base name of the file
- Size int64 // length in bytes for regular files
- ModTime time.Time // modification time
- }
- // Storage provides an API for storing binary data
- type Storage interface {
- // FullPath returns the storage working path combined with the path provided
- FullPath(path string) string
- // Stat returns the StorageStats for the specific path.
- Stat(path string) (*StorageInfo, error)
- // Read uses the relative path of the storage combined with the provided path to
- // read the contents.
- Read(path string) ([]byte, error)
- // Write uses the relative path of the storage combined with the provided path
- // to write a new file or overwrite an existing file.
- Write(path string, data []byte) error
- // Remove uses the relative path of the storage combined with the provided path to
- // remove a file from storage permanently.
- Remove(path string) error
- // Exists uses the relative path of the storage combined with the provided path to
- // determine if the file exists.
- Exists(path string) (bool, error)
- // List uses the relative path of the storage combined with the provided path to return
- // storage information for the files.
- List(path string) ([]*StorageInfo, error)
- }
- // IsNotExist returns true if the error provided from a storage object is DoesNotExist
- func IsNotExist(err error) bool {
- if err == nil {
- return false
- }
- return err.Error() == DoesNotExistError.Error()
- }
|