wfs

package
v8.0.0-...-0f2c8d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadOperation int = iota
	WriteOperation
)

Supported operation modes

Variables

This section is empty.

Functions

func GetType

func GetType(name string, isFolder bool) string

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 AllowPolicy

type AllowPolicy struct{}

AllowPolicy allows all operations

func (AllowPolicy) Comply

func (p AllowPolicy) Comply(path FileID, operation int) bool

Comply method returns true

type CombinedPolicy

type CombinedPolicy struct {
	Policies []Policy
}

CombinedPolicy allows to join multiple policies together

func (CombinedPolicy) Comply

func (p CombinedPolicy) Comply(path FileID, operation int) bool

Comply method returns true only when all joined policies are complied

type DenyPolicy

type DenyPolicy struct{}

DenyPolicy allows all operations

func (DenyPolicy) Comply

func (p DenyPolicy) Comply(path FileID, operation int) bool

Comply method returns false

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) Stats

func (d *DriveFacade) Stats() (uint64, uint64, error)

func (*DriveFacade) WithOperationConfig

func (d *DriveFacade) WithOperationConfig(config *OperationConfig) Drive

WithOperationConfig makes a copy of drive with new operation config

func (*DriveFacade) Write

func (d *DriveFacade) Write(id string, data io.Reader) error

Write saves content to a file

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 FileID

type FileID interface {
	GetPath() string
	ClientID() string
	IsFolder() bool
	Contains(FileID) bool
}

type FileInfo

type FileInfo interface {
	os.FileInfo
	File() FileID
}

type ListConfig

type ListConfig struct {
	SkipFiles  bool
	SubFolders bool
	Nested     bool
	Exclude    MatcherFunc
	Include    MatcherFunc
}

ListConfig contains file listing options

type MatcherFunc

type MatcherFunc func(string) bool

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

func (ReadOnlyPolicy) Comply

func (p ReadOnlyPolicy) Comply(path FileID, operation int) bool

Comply method returns true for read operations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL