Documentation
¶
Overview ¶
Package ssh implements the Storager interface on top of SSH/SFTP. The implementation is inspired by wal-g's pkg/storages/sh.
Index ¶
- type Config
- type SFTPClient
- type Storage
- func (s *Storage) Close() error
- func (s *Storage) Delete(ctx context.Context, filePaths ...string) error
- func (s *Storage) DeleteAll(ctx context.Context, pathPrefix string) error
- func (s *Storage) Dirname() string
- func (s *Storage) Exists(ctx context.Context, fileName string) (bool, error)
- func (s *Storage) GetCwd() string
- func (s *Storage) GetObject(ctx context.Context, filePath string) (reader io.ReadCloser, err error)
- func (s *Storage) ListDir(ctx context.Context) (files []string, dirs []storages.Storager, err error)
- func (s *Storage) PutObject(ctx context.Context, filePath string, body io.Reader) error
- func (s *Storage) Stat(fileName string) (*domains.ObjectStat, error)
- func (s *Storage) SubStorage(subPath string, relative bool) storages.Storager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Host string `mapstructure:"host"` // required
Port int `mapstructure:"port"` // default 22
User string `mapstructure:"user"` // required
Password string `mapstructure:"password"` // auth: password
PrivateKeyPath string `mapstructure:"private_key_path"` // auth: private key
Prefix string `mapstructure:"prefix"` // remote root path
}
type SFTPClient ¶
type SFTPClient interface {
ReadDir(path string) ([]os.FileInfo, error)
Join(elem ...string) string
Remove(path string) error
RemoveDirectory(path string) error
Stat(p string) (os.FileInfo, error)
Open(path string) (*sftp.File, error)
Create(path string) (*sftp.File, error)
MkdirAll(path string) error
}
SFTPClient is the subset of *sftp.Client used by the storage. It is kept as an interface so the dependency surface stays small and explicit.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
func NewStorage ¶
func (*Storage) Close ¶
Close releases the shared SSH/SFTP connection. It must be called once by the lifecycle owner when the storage and all of its sub-storages are no longer needed; otherwise the connection, its receive goroutine and its socket leak until the process exits. SubStorage clones share the same connection, so only the connection is closed (not the clone) — Close is idempotent and safe to call more than once and before the connection has been established.