transport

package
v0.0.0-...-ee25e63 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const SizeAll = -1

Variables

View Source
var SampleConfig = Config{
	SFTP: &SFTPConfig{
		Addr:     "hostname",
		Username: "username",
		Password: "password when not using private key authentication",
		KeyPath:  "path when using private key authentication",
		Base:     "local path on the sftp server",
	},
	S3: &S3Config{
		Region:    "AWS region, i.e. eu-central-1",
		Endpoint:  "S3 endpoint, i.e. s3.eu-central-1.amazonaws.com",
		Bucket:    "S3 bucket name",
		AccessKey: "S3 access key",
		Secret:    "S3 secret key",
	},
}

Functions

func CopyFile

func CopyFile(dest Exchanger, destName string, source Exchanger, sourceName string) error

func LockFile

func LockFile(e Exchanger, name string, span time.Duration) (uint64, error)

func ReadFile

func ReadFile(e Exchanger, name string) ([]byte, error)

func ReadJSON

func ReadJSON(e Exchanger, name string, v any, hash hash.Hash) error

func UnlockFile

func UnlockFile(e Exchanger, name string, id uint64)

func WriteFile

func WriteFile(e Exchanger, name string, data []byte) error

func WriteJSON

func WriteJSON(e Exchanger, name string, v any, hash hash.Hash) error

Types

type Config

type Config struct {
	SFTP  *SFTPConfig  `json:"sftp,omitempty" yaml:"sftp,omitempty"`
	S3    *S3Config    `json:"s3,omitempty" yaml:"s3,omitempty"`
	Local *LocalConfig `json:"local,omitempty" yaml:"local,omitempty"`
}

func ReadConfig

func ReadConfig(name string) (Config, error)

type Exchanger

type Exchanger interface {

	//Touched returns true when some data has been written to the exchanger since the last time Touched was called
	Touched(name string) bool

	// Read reads data from a file into a writer
	Read(name string, rang *Range, dest io.Writer) error

	// Write writes data to a file name. An existing file is overwritten
	Write(name string, source io.Reader) error

	//ReadDir returns the entries of a folder content
	ReadDir(name string, opts ListOption) ([]fs.FileInfo, error)

	// Stat provides statistics about a file
	Stat(name string) (os.FileInfo, error)

	// Rename a file. Overwrite an existing file if present
	Rename(old, new string) error

	// Delete deletes a file
	Delete(name string) error

	// Close releases resources
	Close() error

	// String returns a human-readable representation of the storer (e.g. sftp://user@host.cc/path)
	String() string
}

Exchanger is a low level interface to storage services such as S3 or SFTP

func NewExchanger

func NewExchanger(c Config) (Exchanger, error)

NewExchanger creates a new exchanger giving a provided configuration

func NewLocal

func NewLocal(config LocalConfig) (Exchanger, error)

func NewS3

func NewS3(c S3Config) (Exchanger, error)

func NewSFTP

func NewSFTP(config SFTPConfig) (Exchanger, error)

type ListOption

type ListOption uint32
const (
	// IncludeHiddenFiles includes hidden files in a list operation
	IncludeHiddenFiles ListOption = 1
	// IsPrefix matches all the files starting with the path
	IsPrefix = 2
)

type Local

type Local struct {
	// contains filtered or unexported fields
}

func (*Local) Close

func (l *Local) Close() error

func (*Local) Delete

func (l *Local) Delete(name string) error

func (*Local) Read

func (l *Local) Read(name string, rang *Range, dest io.Writer) error

func (*Local) ReadDir

func (l *Local) ReadDir(name string, opts ListOption) ([]fs.FileInfo, error)

func (*Local) Rename

func (l *Local) Rename(old, new string) error

func (*Local) Stat

func (l *Local) Stat(name string) (os.FileInfo, error)

func (*Local) String

func (l *Local) String() string

func (*Local) Touched

func (l *Local) Touched(name string) bool

func (*Local) Write

func (l *Local) Write(name string, source io.Reader) error

type LocalConfig

type LocalConfig struct {
	Base string `json:"base" yaml:"base"`
}

type Range

type Range struct {
	From int64
	To   int64
}

type S3

type S3 struct {
	// contains filtered or unexported fields
}

func (*S3) Close

func (s *S3) Close() error

func (*S3) Delete

func (s *S3) Delete(name string) error

func (*S3) Read

func (s *S3) Read(name string, rang *Range, dest io.Writer) error

func (*S3) ReadDir

func (s *S3) ReadDir(prefix string, opts ListOption) ([]fs.FileInfo, error)

func (*S3) Rename

func (s *S3) Rename(old, new string) error

func (*S3) Stat

func (s *S3) Stat(name string) (fs.FileInfo, error)

func (*S3) String

func (s *S3) String() string

func (*S3) Touched

func (s *S3) Touched(name string) bool

func (*S3) Write

func (s *S3) Write(name string, source io.Reader) error

type S3Config

type S3Config struct {
	Region     string `json:"region" yaml:"region"`
	Endpoint   string `json:"endpoint" yaml:"endpoint"`
	Bucket     string `json:"bucket" yaml:"bucket"`
	AccessKey  string `json:"accessKey" yaml:"accessKey"`
	Secret     string `json:"secret" yaml:"secret"`
	DisableSSL bool   `json:"disableSSL" yaml:"disableSSL"`
}

type SFTP

type SFTP struct {
	// contains filtered or unexported fields
}

func (*SFTP) Close

func (s *SFTP) Close() error

func (*SFTP) Delete

func (s *SFTP) Delete(name string) error

func (*SFTP) Read

func (s *SFTP) Read(name string, rang *Range, dest io.Writer) error

func (*SFTP) ReadDir

func (s *SFTP) ReadDir(prefix string, opts ListOption) ([]fs.FileInfo, error)

func (*SFTP) Rename

func (s *SFTP) Rename(old, new string) error

func (*SFTP) Stat

func (s *SFTP) Stat(name string) (os.FileInfo, error)

func (*SFTP) String

func (s *SFTP) String() string

func (*SFTP) Touched

func (s *SFTP) Touched(name string) bool

func (*SFTP) Write

func (s *SFTP) Write(name string, source io.Reader) error

type SFTPConfig

type SFTPConfig struct {
	Addr     string `json:"addr" yaml:"addr"`
	Username string `json:"username" yaml:"username"`
	Password string `json:"password" yaml:"password"`
	KeyPath  string `json:"keyPath" yaml:"keyPath"`
	Base     string `json:"base" yaml:"base"`
}

type Source

type Source struct {
	Name   string
	Data   []byte
	Reader io.Reader
	Size   int64
}

Jump to

Keyboard shortcuts

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