2017-05-11 16:39:54 +02:00
|
|
|
package sftp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Interfaces are differentiated based on required returned values.
|
|
|
|
// All input arguments are to be pulled from Request (the only arg).
|
|
|
|
|
2018-06-17 18:59:12 +02:00
|
|
|
// The Handler interfaces all take the Request object as its only argument.
|
|
|
|
// All the data you should need to handle the call are in the Request object.
|
|
|
|
// The request.Method attribute is initially the most important one as it
|
|
|
|
// determines which Handler gets called.
|
|
|
|
|
2018-03-19 16:51:38 +01:00
|
|
|
// FileReader should return an io.ReaderAt for the filepath
|
|
|
|
// Note in cases of an error, the error text will be sent to the client.
|
2018-06-17 18:59:12 +02:00
|
|
|
// Called for Methods: Get
|
2017-05-11 16:39:54 +02:00
|
|
|
type FileReader interface {
|
2017-09-30 16:27:27 +02:00
|
|
|
Fileread(*Request) (io.ReaderAt, error)
|
2017-05-11 16:39:54 +02:00
|
|
|
}
|
|
|
|
|
2018-03-19 16:51:38 +01:00
|
|
|
// FileWriter should return an io.WriterAt for the filepath.
|
|
|
|
//
|
|
|
|
// The request server code will call Close() on the returned io.WriterAt
|
|
|
|
// ojbect if an io.Closer type assertion succeeds.
|
|
|
|
// Note in cases of an error, the error text will be sent to the client.
|
2018-06-17 18:59:12 +02:00
|
|
|
// Called for Methods: Put, Open
|
2017-05-11 16:39:54 +02:00
|
|
|
type FileWriter interface {
|
2017-09-30 16:27:27 +02:00
|
|
|
Filewrite(*Request) (io.WriterAt, error)
|
2017-05-11 16:39:54 +02:00
|
|
|
}
|
|
|
|
|
2018-03-19 16:51:38 +01:00
|
|
|
// FileCmder should return an error
|
|
|
|
// Note in cases of an error, the error text will be sent to the client.
|
2018-06-17 18:59:12 +02:00
|
|
|
// Called for Methods: Setstat, Rename, Rmdir, Mkdir, Symlink, Remove
|
2017-05-11 16:39:54 +02:00
|
|
|
type FileCmder interface {
|
2017-09-30 16:27:27 +02:00
|
|
|
Filecmd(*Request) error
|
2017-05-11 16:39:54 +02:00
|
|
|
}
|
|
|
|
|
2018-03-19 16:51:38 +01:00
|
|
|
// FileLister should return an object that fulfils the ListerAt interface
|
|
|
|
// Note in cases of an error, the error text will be sent to the client.
|
2018-06-17 18:59:12 +02:00
|
|
|
// Called for Methods: List, Stat, Readlink
|
2017-09-30 16:27:27 +02:00
|
|
|
type FileLister interface {
|
|
|
|
Filelist(*Request) (ListerAt, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListerAt does for file lists what io.ReaderAt does for files.
|
|
|
|
// ListAt should return the number of entries copied and an io.EOF
|
|
|
|
// error if at end of list. This is testable by comparing how many you
|
|
|
|
// copied to how many could be copied (eg. n < len(ls) below).
|
|
|
|
// The copy() builtin is best for the copying.
|
2018-03-19 16:51:38 +01:00
|
|
|
// Note in cases of an error, the error text will be sent to the client.
|
2017-09-30 16:27:27 +02:00
|
|
|
type ListerAt interface {
|
|
|
|
ListAt([]os.FileInfo, int64) (int, error)
|
2017-05-11 16:39:54 +02:00
|
|
|
}
|