Documentation ¶
Index ¶
- Constants
- func GetType(name string, isFolder bool) string
- type Adapter
- type AllowPolicy
- type CombinedPolicy
- type DenyPolicy
- type Drive
- type DriveConfig
- type DriveFacade
- func (d *DriveFacade) Copy(source, target, name string) (string, error)
- func (d *DriveFacade) Exists(id string) bool
- func (d *DriveFacade) Info(id string) (File, error)
- func (d *DriveFacade) List(id string, config ...*ListConfig) ([]File, error)
- func (d *DriveFacade) Make(id, name string, isFolder bool) (string, error)
- func (d *DriveFacade) Move(source, target, name string) (string, error)
- func (d *DriveFacade) Read(id string) (io.ReadSeeker, error)
- func (d *DriveFacade) Remove(id string) error
- func (d *DriveFacade) Search(id, search string, config ...*ListConfig) ([]File, error)
- func (d *DriveFacade) Stats() (uint64, uint64, error)
- func (d *DriveFacade) WithOperationConfig(config *OperationConfig) Drive
- func (d *DriveFacade) Write(id string, data io.Reader) error
- type File
- type FileID
- type FileInfo
- type ListConfig
- type MatcherFunc
- type OperationConfig
- type Policy
- type ReadOnlyPolicy
Constants ¶
const ( ReadOperation int = iota WriteOperation )
Supported operation modes
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter interface { // implements Policy Comply(FileID, int) bool // converts client id <-> server id ToFileID(id string) FileID GetParent(f FileID) FileID // file operations List(id FileID) ([]FileInfo, error) Search(id FileID, search string) ([]FileInfo, error) Remove(id FileID) error Read(id FileID) (io.ReadSeeker, error) Write(id FileID, data io.Reader) error Make(id FileID, name string, isFolder bool) (FileID, error) Copy(source, target FileID, name string, isFolder bool) (FileID, error) Move(source, target FileID, name string, isFolder bool) (FileID, error) Info(id FileID) (FileInfo, error) Exists(id FileID, name string) bool Stats() (uint64, uint64, error) }
type CombinedPolicy ¶
type CombinedPolicy struct {
Policies []Policy
}
CombinedPolicy allows to join multiple policies together
type Drive ¶
type Drive interface { List(id string, config ...*ListConfig) ([]File, error) Search(id, search string, config ...*ListConfig) ([]File, error) Remove(id string) error Read(id string) (io.ReadSeeker, error) Write(id string, data io.Reader) error Exists(id string) bool Info(id string) (File, error) Make(id, name string, isFolder bool) (string, error) Copy(source, target, name string) (string, error) Move(source, target, name string) (string, error) Stats() (uint64, uint64, error) }
File stores info about single file
func NewDrive ¶
func NewDrive(adapter Adapter, config *DriveConfig) Drive
NewLocalDrive returns new LocalDrive object which represents the file folder on local drive due to ForceRootPolicy all operations outside of the root folder will be blocked
type DriveConfig ¶
type DriveConfig struct { Verbose bool List *ListConfig Operation *OperationConfig Policy *Policy }
DriveConfig contains drive configuration
type DriveFacade ¶
type DriveFacade struct {
// contains filtered or unexported fields
}
Drive represents an isolated file system
func (*DriveFacade) Copy ¶
func (d *DriveFacade) Copy(source, target, name string) (string, error)
Copy makes a copy of file or a folder
func (*DriveFacade) Exists ¶
func (d *DriveFacade) Exists(id string) bool
Exists checks is file / folder with defined path does exist
func (*DriveFacade) Info ¶
func (d *DriveFacade) Info(id string) (File, error)
Info returns info about a single file / folder
func (*DriveFacade) List ¶
func (d *DriveFacade) List(id string, config ...*ListConfig) ([]File, error)
List method returns array of files from the target folder
func (*DriveFacade) Make ¶
func (d *DriveFacade) Make(id, name string, isFolder bool) (string, error)
Mkdir creates a new folder
func (*DriveFacade) Move ¶
func (d *DriveFacade) Move(source, target, name string) (string, error)
Move renames(moves) a file or a folder
func (*DriveFacade) Read ¶
func (d *DriveFacade) Read(id string) (io.ReadSeeker, error)
Read returns content of a file
func (*DriveFacade) Remove ¶
func (d *DriveFacade) Remove(id string) error
Remove deletes a file or a folder
func (*DriveFacade) Search ¶
func (d *DriveFacade) Search(id, search string, config ...*ListConfig) ([]File, error)
func (*DriveFacade) WithOperationConfig ¶
func (d *DriveFacade) WithOperationConfig(config *OperationConfig) Drive
WithOperationConfig makes a copy of drive with new operation config
type File ¶
type File struct { Name string `json:"value"` ID string `json:"id"` Size int64 `json:"size"` Date int64 `json:"date"` Type string `json:"type"` Files []File `json:"data,omitempty"` }
File stores info about single file
type ListConfig ¶
type ListConfig struct { SkipFiles bool SubFolders bool Nested bool Exclude MatcherFunc Include MatcherFunc }
ListConfig contains file listing options
type MatcherFunc ¶
MatcherFunc receives path and returns true if path matches the rule
type OperationConfig ¶
type OperationConfig struct {
PreventNameCollision bool
}
OperationConfig contains file operation options
type Policy ¶
type Policy interface { // Comply method returns true is operation for the path is allowed Comply(FileID, int) bool }
Policy is a rule which allows or denies operation
type ReadOnlyPolicy ¶
type ReadOnlyPolicy struct{}
ReadOnlyPolicy allows read access and blocks any modifications